The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep count across multiple files CrunchMunch UNIX for Advanced & Expert Users 4 05-15-2008 12:47 AM
to grep and find the count arunkumar_mca UNIX for Dummies Questions & Answers 4 11-12-2007 07:55 AM
count on the grep sudheshnaiyer UNIX for Dummies Questions & Answers 2 08-05-2007 06:11 AM
grep and count no of occurences in every line of a file srikanthgr1 Shell Programming and Scripting 12 04-20-2007 06:16 AM
Grep, count and match two files madhunk Shell Programming and Scripting 19 05-31-2006 11:52 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2007
Registered User
 

Join Date: Jan 2007
Posts: 8
Grep with count

I need to count the number of instances of a dir in a set of dir with the same suffix .txt (one dir and all recursive directories).

<Main Dir>
<sub_dir1>
<sub_dir2>
<sub_dir3>
<sub_dir4>

and count the number of instances of a type of file, ie/ .txt files
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-16-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,448
Code:
ls -R1 *.txt |wc -l
Reply With Quote
  #3 (permalink)  
Old 04-16-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
find /dir -type f -name "*.txt" | wc -l

Cheers
ZB
Reply With Quote
  #4 (permalink)  
Old 04-16-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,226
This will count files with the same extension...
Code:
find . -type f -print|awk '{print match($0,/\.[^/]*$/)?substr($0,RSTART,RLENGTH):"No Ext"}'|sort|uniq -c
...which gives...
Code:
     12 .env
      7 .gif
      2 .htm
     26 .html
      8 .inf
      2 .ini

Last edited by Ygor; 04-16-2007 at 07:39 PM.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0