Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a search command that will look for strings inside text files

Status
Not open for further replies.

itr0754

Technical User
Dec 17, 2002
58
PR
I want to run a search on a directory with several text files looking for a specific text string. How can I do this on AIX 4.3.3 ??
 
find . -print |xargs grep "mystring"

will find the string in the current directory and all subdirectories. If you are only interested in the current directory, just do a grep "mystring"
 
Another option to try is the following....

find /somedir -exec grep "searchstring" {} /dev/null \;

Short explanation about the "/dev/null" thing...
If you leave it out, the command will return all the search strings, but it will not tell you in which file it resides. By default grep will return the filename and the matching line if you search in more than one file at a time, e.g.
grep someting *.txt. So by adding /dev/null, you are actually looking in two files. /dev/null will never contain the pattern that you are looking for, so it is safe.

Careful, this command does not perform the same on all flavours on UNIX.

Also be sure that all the files in the directory are text files.

Also, unless you have endless amounts of time, do not run it against the /dev directory.

You can also modify the find command to look for more specific files, e.g.

find /somedir -name "*.txt" -exec grep "searchpattern" {} /dev/null \;

Cheers
Obie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top