The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 04:47 AM
to grep and find the count arunkumar_mca UNIX for Dummies Questions & Answers 4 11-12-2007 11:55 AM
count on the grep sudheshnaiyer UNIX for Dummies Questions & Answers 2 08-05-2007 10:11 AM
grep and count no of occurences in every line of a file srikanthgr1 Shell Programming and Scripting 12 04-20-2007 10:16 AM
Grep, count and match two files madhunk Shell Programming and Scripting 19 05-31-2006 03:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-16-2007
t4st33@mac.com t4st33@mac.com is offline
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
  #2 (permalink)  
Old 04-16-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,539
Code:
ls -R1 *.txt |wc -l
  #3 (permalink)  
Old 04-16-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

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

Cheers
ZB
  #4 (permalink)  
Old 04-16-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
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 11:39 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0