0

We have hourly and daily files in the same folder:

data-2015-06-06-00.tsv
data-2015-06-06-01.tsv
data-2015-06-06-02.tsv
data-2015-06-06-03.tsv
data-2015-06-06.tsv
data-2015-06-07-03.tsv
data-2015-06-07-02.tsv
data-2015-06-07.tsv

How to get the only daily from the list of files.

i need only data-2015-06-06.tsv data-2015-06-07.tsv

2 Answers2

3

today's :

 ls date-$(date +%Y-%m-%d)*

yesterday's :

 ls date-$(date +%Y-%m-%d -d yesterday )*

where

  • date +%Y-%m-%d will format date
  • -d yesterday use yesterday's date
  • $( ) construct, run command and use output as a string

I assume you can't relay on files last modification times.

Edit:

to avoid hourly from today:

 ls date-$(date +%Y-%m-%d).tsv

to get only daily use @lcd047 's answer.

Archemar
  • 31,554
3

Three more options:

ls  | grep ^data-...........tsv  

or:

ls  | grep ^data-"[[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}.tsv"

or:

ls  | grep ^data-[1-2][0-1][0-9][0-9]-[0-1][0-9]-[0-1][0-9].tsv
jcbermu
  • 4,736
  • 18
  • 26
  • see http://unix.stackexchange.com/questions/128985/why-not-parse-ls, you can replace ls | grep ^FOO by ls FOO in most case (expect dot), where FOO is above regexp. – Archemar Jul 09 '15 at 12:29