![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep command | christine33990 | UNIX for Dummies Questions & Answers | 11 | 05-06-2008 02:45 AM |
| how to exclude the GREP command from GREP | yamsin789 | UNIX for Advanced & Expert Users | 2 | 10-05-2007 02:59 AM |
| grep command help | ishmael^soyuz | Shell Programming and Scripting | 4 | 07-11-2007 09:01 AM |
| grep command | pmsuper | UNIX for Dummies Questions & Answers | 6 | 11-22-2006 07:12 AM |
| grep command | debasis.mishra | Shell Programming and Scripting | 1 | 03-28-2006 01:53 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
|
|||||
|
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 10: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 10: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. |
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|