The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find , grep james94538 UNIX for Dummies Questions & Answers 3 10-09-2008 06:03 PM
grep, find or awk? netrom UNIX for Dummies Questions & Answers 4 04-09-2008 02:03 PM
grep and find MEllis5 UNIX for Dummies Questions & Answers 1 04-07-2008 05:16 AM
find then grep flame_eagle Shell Programming and Scripting 7 03-13-2008 08:19 AM
find & grep Anika UNIX for Dummies Questions & Answers 11 02-01-2001 09:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-10-2006
Registered User
 

Join Date: Aug 2005
Posts: 45
find and grep

Hi,
I need to find out a particular pattern from a directory, for example say X.

The X directory contains 10 c files, and it has subdirectory called Y, and Y has 20 c files within it.

Now I have to find out the pattern only from parent directory X not from sub directory Y.

I have used this type of command

X> find . -name "*" | xargs grep -l "getsum"

It will retrive result from sub directory also.....I need only for the parent dir.

Thanks
Sarwan
Reply With Quote
Forum Sponsor
  #2  
Old 04-10-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
then specify that in the find command itself

find X/ -name "*" | xargs grep -l "getsum"

X/ - the dir from where u want to search.
Reply With Quote
  #3  
Old 04-10-2006
Registered User
 

Join Date: Aug 2005
Posts: 45
find X/ -name "*" | xargs grep -l "getsum"

This one also retrives pattern file name from the sub directory.

find X/ -name "*" | xargs grep -l "getsum" it gives the same o/p as this
find . -name "*" | xargs grep -l "getsum".

Last edited by sarwan; 04-10-2006 at 02:22 AM. Reason: More clarity
Reply With Quote
  #4  
Old 04-10-2006
Registered User
 

Join Date: Jan 2006
Posts: 59
Whether you give absolute or relative path, find drills down into all the subdirectories starting from the path specified.

So you may as well try out,

find . \( ! -name . -prune \) -type f | xargs grep -l "pattern"

"prune" prevents going into sub-directories.

Last edited by manthasirisha; 04-10-2006 at 02:52 AM. Reason: typo error
Reply With Quote
  #5  
Old 04-10-2006
Registered User
 

Join Date: Sep 2005
Location: india
Posts: 78
X> ls *.c | xargs grep "getsum"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:26 AM.


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

Content Relevant URLs by vBSEO 3.2.0