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 > 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 09:03 PM
grep, find or awk? netrom UNIX for Dummies Questions & Answers 4 04-09-2008 05:03 PM
grep and find MEllis5 UNIX for Dummies Questions & Answers 1 04-07-2008 08:16 AM
find then grep flame_eagle Shell Programming and Scripting 7 03-13-2008 11:19 AM
find & grep Anika UNIX for Dummies Questions & Answers 11 02-01-2001 12:19 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-10-2006
sarwan sarwan is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 54
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
  #2 (permalink)  
Old 04-10-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
then specify that in the find command itself

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

X/ - the dir from where u want to search.
  #3 (permalink)  
Old 04-10-2006
sarwan sarwan is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 54
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 05:22 AM.. Reason: More clarity
  #4 (permalink)  
Old 04-10-2006
manthasirisha manthasirisha is offline
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 05:52 AM.. Reason: typo error
  #5 (permalink)  
Old 04-10-2006
Raom Raom is offline
Registered User
  
 

Join Date: Sep 2005
Location: india
Posts: 79
X> ls *.c | xargs grep "getsum"
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 08:45 AM.


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