Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello!
I'm wondering if some one could help me with the following with a UNIX shell scripting.
a) I want to count the files according to the date. Please find the details as follows,
Oct 15, 2009 - 3 files
Oct 14, 2009 - 2 files
.........
.........
Oct 14, 2008 - 4 files
........
........I just need the files count on a particular day and the date should indicate the "Month Day, Year - No. of files" in the result. I tried, but i'm not able to get the year in the result.
Your help would be greatly appreciated.
Thanks

Hi Nails,
please find this.
ls -lt | grep "^-" | awk '{Date_count=$6" "$7; freq[Date_count]++}END {for (date in freq) printf "%s\t%d\n", date, freq[date] }'i have this , but it's not giving me what i want. Please help me with this.
Thanks!!

You did the hard part. Remember that on legacy Unix systems that the ls command for the first 6 months shows the time instead of the year. (GNU ls has an option to show the year). Therefore you may have trouble with this script in the 4th quarter:
ls -lt | grep "^-" | awk '{ if($8 ~ /:/) $8=2009 Date_count=$6" "$7", "$8 freq[Date_count]++} END {for (date in freq) printf "%s\t%d\n", date, freq[date] }'

Hi Nails!
This is great solution for my issue. I have tried your modified script and i get results as i expected even though the year doesn't show up for the first 6 months, and i'm happy for that.
Thank you.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |