![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep command | christine33990 | UNIX for Dummies Questions & Answers | 11 | 05-05-2008 11:45 PM |
| how to exclude the GREP command from GREP | yamsin789 | UNIX for Advanced & Expert Users | 2 | 10-04-2007 11:59 PM |
| grep command help | ishmael^soyuz | Shell Programming and Scripting | 4 | 07-11-2007 06:01 AM |
| grep command | pmsuper | UNIX for Dummies Questions & Answers | 6 | 11-22-2006 03:12 AM |
| grep command | debasis.mishra | Shell Programming and Scripting | 1 | 03-27-2006 10:53 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
grep command-HELP?!
Hello all
I am having trouble with the grep command. I want to find the word "blue" - ( the word blue in a sentence in the file) in numerous files and directories. I have tried every combo to get there. Can anyone help? I am not going to try to pretend this isn't a homeowrk question.. but believe me I have spent a lot of time trying this to no avail Rob |
| Forum Sponsor | ||
|
|
|
||||
|
I still don't think it's more expensive. The grep processes won't stack either, so you'll not see hundreds in your proc table. Just as a quick example under a solaris dir with 4 files, using truss to watch the lib calls etc.:
$ truss find . -type f 2>&1 | xargs grep ls 2>&1 | wc -l 378 $ truss find . -type f -exec grep ls {} \; 2>&1 | wc -l 49 The xargs still seems to be the more expensive choice. Cheers, Keith Last edited by kduffin; 11-17-2003 at 06:29 PM. |
|
||||
|
One thing that the xargs example does do better is that it will show the filenames where as the exec won't. You'd have to have a wrapper that echo's the filename and does a grep for the exec to work effectively.
$ find . -type f | xargs grep ls ./ick1:ls ./ick2:ls ./ick3:ls $ find . -type f -exec grep ls {} \; ls ls ls $ Cheers, Keith Last edited by kduffin; 11-17-2003 at 06:30 PM. |
|
||||
|
Quote:
cd /usr/bin time find . -print | xargs grep "bogusstring" > /dev/null time find . -exec grep "bogusstring" {} \; > /dev/null Because the commands are running as non-root and we did not redirect stderr you will see a few error messages. Notice the difference in the speed at which are displayed. And then compare the numbers. By using xargs, you prevented hundreds of fork() and hundreds of exec() system calls. Neither system call is cheap. |
||||
| Google UNIX.COM |