Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing how many files with the "same" name. 1

Status
Not open for further replies.

lhg1

IS-IT--Management
Mar 29, 2005
134
DK
Hi

I have a dir that has a lot of log files, one from every hour. I would like to count how many logfiles with the same start of the name.

This is how the files look.
hildir-20071125_230704
hildir-20071126_000702
hildir-20071126_010702
hildir-20071126_020706
hildir-20071126_030704
hildir-20071126_040702
elwood-20071126_010708
elwood-20071126_020703
elwood-20071126_030705
elwood-20071126_040704
elwood-20071126_050704


So the result of this should be

hildir 6
elwood 5

I should mention that there are in fact a lot more files
> ls|grep hildir|wc -l
9298


Any boddy have any good ideers?

/lhg
 
ls hildir* | wc -l
ls elwood* | wc -l
etc...

I want to be good, is that not enough?
 
ls | awk -F- '{++a[$1]}END{for(i in a)print i,a}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Fantastick - PHV

That is a great solution.

/larshg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top