Counting items per ...
 

MegaSack DRAW - This year's winner is user - rgwb
We will be in touch

[Closed] Counting items per day in a folder

10 Posts
4 Users
0 Reactions
53 Views
Posts: 0
Free Member
Topic starter
 

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?


 
Posted : 26/04/2018 1:17 pm
Posts: 12704
Free Member
 

.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


 
Posted : 26/04/2018 1:43 pm
Posts: 0
Free Member
 

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


 
Posted : 26/04/2018 1:46 pm
Posts: 0
Free Member
 

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


 
Posted : 26/04/2018 1:51 pm
Posts: 0
Free Member
Topic starter
 

find . -type f -print0 works, can't get the sort and date stuff to work yet. Mac terminal obviously a bit different to linux.


 
Posted : 26/04/2018 2:04 pm
Posts: 0
Free Member
Topic starter
 

Doesn't understand '%TY-%Tm-%Td\n'


 
Posted : 26/04/2018 2:05 pm
Posts: 3735
Free Member
 

Try +%Y-%m-%d


 
Posted : 26/04/2018 2:08 pm
Posts: 0
Free Member
 

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.


 
Posted : 26/04/2018 2:12 pm
Posts: 0
Free Member
Topic starter
 

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.


 
Posted : 26/04/2018 2:26 pm
Posts: 0
Free Member
 

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]
}'


 
Posted : 26/04/2018 2:32 pm
Posts: 0
Free Member
Topic starter
 

sorted, I can save terminal output and there's ways to import to excel with the spaces.

Cheers for the help. 🙂


 
Posted : 26/04/2018 2:36 pm