1

I have a directory with n files in it, all starting with a date in format yyyymmdd.

Example:

20210208_bla.txt
20210208_bla2.txt
20210209_bla.txt

I want know how many files of a certain date I have, so output should be like:

20210208 112
20210209 96
20210210 213
...

Or at least find the different beginnings of the actual files (=the different dates) in my folder.

Thanks

Hyperhyper
  • 17
  • 3

1 Answers1

2

A very simple solution would be to do something like:

ls | cut -f 1 -d _ | sort -n | uniq -c

With your example this gives:

 2 20210208
 1 20210209

Update: If you need to swap the two columns you can follow: https://stackoverflow.com/a/11967849/2001017

ls | cut -f 1 -d _ | sort -n | uniq -c | awk '{ t = $1; $1 = $2; $2 = t; print; }' 

which prints:

20210208 2
20210209 1
Picaud Vincent
  • 8,544
  • 4
  • 19
  • 55