MegaSack DRAW - This year's winner is user - rgwb
We will be in touch
Weird request this one.
I've got a folder on my mac desktop (can fire on to pc if this is easier)
But I want to count the items in it by date.
Ie
1st april - 26 (files)
2nd april - 15
3rd april - 20
on so on...
Any ideas?
.bat file to create csv of all files and dates.
Open it in excel. Count them.
Is it a one off?
In windoes you can right click on some white space in the folder and group by date.
But that gets a bit vague over a week ago
If you are on a Mac then use a script. A bit of searching comes up with this for ubuntu but there should be something similar for the Mac shell
find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c
-type f = files only
The above command is recursive - I just ran it on my home folder and it took about 20 seconds to complete. If you only want to do the current folder and not subfolders then.
find . -maxdepth 1 -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c
find . -type f -print0 works, can't get the sort and date stuff to work yet. Mac terminal obviously a bit different to linux.
Doesn't understand '%TY-%Tm-%Td\n'
Try +%Y-%m-%d
OK, Apple must use a different set of options to the find command. I can check when I get home to see what works. The %Ty etc is a format string to -printf. Is there anything in the man entry for find that mentions printf?
Edit: there's a copy of the Apple man page here https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/find.1.html
What the line does is find all files in the current folder and for each one prints out its last modified date. That's piped through sort and then through uniq, the -c flag tells uniq to prepend each line with the count.
ls -llt
That gives me an output I can just fire into excel and make a pivot table (The desired result tbh.)
Any way I can make that output comma separated? instead of spaces. So I can copy and paste into a text file and import into excel.
If you want to split the output of 'ls' then you'll need Sed or Awk. Here's a short script using bash (I can't remember if the Mac needs the #! line)
#!/bin/bash
ls -l | grep "^-" | awk '{
key=$6$7
freq[key]++
}
END {
for (date in freq)
printf "%s,%d\n", date, freq[date]
}'
sorted, I can save terminal output and there's ways to import to excel with the spaces.
Cheers for the help. 🙂
