![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
X> ls *.c | xargs grep "getsum"
|
|||
| Google The UNIX and Linux Forums |