| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
|
| I've been trying to search for a text sting in all files on the drive. The following works , BUT the actual file name is not returned (only the string occurence is printed). What else do I need??? find /opt/icor/fx -exec grep "text string" {} \; Thanks a llot, Mark |
|
#2
|
| On 6/12/2007 3:34 PM, markg9-at-yahoo.com wrote: > I've been trying to search for a text sting in all files on the drive. > The following works , BUT the actual file name is not returned (only > the string occurence is printed). What else do I need??? > > find /opt/icor/fx -exec grep "text string" {} \; find /opt/icor/fx -exec grep -H "text string" {} \; "man grep" ist your friend. S. -- Stefan Naewe stefan dot naewe at atlas-elektronik dot com Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please http://www.expita.com/nomime.html |
|
#3
|
| markg9-at-yahoo.com wrote: > I've been trying to search for a text sting in all files on the drive. > The following works , BUT the actual file name is not returned (only > the string occurence is printed). What else do I need??? > > find /opt/icor/fx -exec grep "text string" {} \; The problem is that grep only prints the file name if more than one file is specified. "find", as used above, will call grep for each file it finds. With GNU grep (/use/sfw/bin/ggrep on Solaris 10), you can use its -H option to print the file name even if only one file is specified. A workaround for standard Solaris grep is: grep "pattern" /dev/null Feeding each file to a separate grep process is highly inefficient, too, so the optimal solution would be: find /opt/icor/fx -exec grep "text string" /dev/null {} + With "+", find will feed groups of file names to the grep sub-process. You still use the /dev/null hack (or ggrep -H) for the case where only one file is found by "find", or where find's grouping would result in the last file being found the only one on grep's command line. mp. -- Systems Administrator | Institute of Scientific Computing | Univ. of Vienna | http://www.par.univie.ac.at/solaris/pca/ Patch Check Advanced | Analyze, download and install patches for Sun Solaris |
|
#4
|
| markg9-at-yahoo.com wrote: > I've been trying to search for a text sting in all files on the drive. > The following works , BUT the actual file name is not returned (only > the string occurence is printed). What else do I need??? > > find /opt/icor/fx -exec grep "text string" {} \; If grep is given more than 1 filename to search it will print the filename before the match. The trick is to thus: grep pattern /dev/null filename so that /dev/null acts as an empty place holder. Note you can also use "+" instead of ";" to reduce the exernal command invocation load (see man page for find(1)). find /path -exec grep pattern /dev/null '{}' '+' hth t |
|
#5
|
| Stefan Naewe wrote: > On 6/12/2007 3:34 PM, markg9-at-yahoo.com wrote: >> I've been trying to search for a text sting in all files on the drive. >> The following works , BUT the actual file name is not returned (only >> the string occurence is printed). What else do I need??? >> >> find /opt/icor/fx -exec grep "text string" {} \; > > find /opt/icor/fx -exec grep -H "text string" {} \; > > "man grep" ist your friend. Note that -H is for the GNU or BSD grep: native Solaris grep does not understand -H. hth t |
|
#6
|
| markg9-at-yahoo.com wrote: > I've been trying to search for a text sting in all files on the drive. > The following works , BUT the actual file name is not returned (only > the string occurence is printed). What else do I need??? > > find /opt/icor/fx -exec grep "text string" {} \; > Another approach maybe. It's faster too find /opt/icor/fx |
|
#7
|
| markg9-at-yahoo.com writes: >I've been trying to search for a text sting in all files on the drive. >The following works , BUT the actual file name is not returned (only >the string occurence is printed). What else do I need??? >find /opt/icor/fx -exec grep "text string" {} \; find /opt/icor/fx -exec grep "text string" {} + Casper -- Expressed in this posting are my opinions. They are in no way related to opinions held by my employer, Sun Microsystems. Statements on Sun products included here are not gospel and may be fiction rather than truth. |
|
#8
|
| On Jun 12, 3:34 pm, mar...@yahoo.com wrote: > I've been trying to search for a text sting in all files on the drive. > The following works , BUT the actual file name is not returned (only > the string occurence is printed). What else do I need??? > > find /opt/icor/fx -exec grep "text string" {} \; find path/to/wherever -type f | xargs grep lists this one doesnt even execute grep for every file found, and finds only files. HTH charlie -- ..sigh |
|
#9
|
| "Thommy M. Malmström" > markg9-at-yahoo.com wrote: >> I've been trying to search for a text sting in all files on the drive. >> The following works , BUT the actual file name is not returned (only >> the string occurence is printed). What else do I need??? >> >> find /opt/icor/fx -exec grep "text string" {} \; >> > Another approach maybe. It's faster too > find /opt/icor/fx It's no faster than the '+' version shown, and it will fail by default on filenames that have spaces or newlines in the name. -- Darren Dunham ddunham-at-taos.com Senior Technical Consultant TAOS http://www.taos.com/ Got some Dr Pepper? San Francisco, CA bay area < This line left intentionally blank to confuse you. > |
|
#10
|
| Darren Dunham wrote: > "Thommy M. Malmström" >> markg9-at-yahoo.com wrote: >>> I've been trying to search for a text sting in all files on the drive. >>> The following works , BUT the actual file name is not returned (only >>> the string occurence is printed). What else do I need??? >>> >>> find /opt/icor/fx -exec grep "text string" {} \; >>> > >> Another approach maybe. It's faster too > >> find /opt/icor/fx > > It's no faster than the '+' version shown, and it will fail by default > on filenames that have spaces or newlines in the name. Well, the '+' thing is a little new to me... |
![]() |
| Thread Tools | |
| Display Modes | |