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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List files with certain search characters

Status
Not open for further replies.

jmanj

Programmer
May 20, 2003
298
US
I'm a biginner with unix and hope somebody can help me with searching files that contains certain words or characters.

I simply want to know what command I will use to list all files in a directory that has the word "500-PROCESS-CREATE"
in it.

Thanks for any help.
 
man find

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Create a little script.
$ cat findstring
Code:
str=$1                        
ls [A-Z]* >flist              
for i in `cat flist`          
do                            
echo $i                       
found=`grep $str $i` 
if [ "$found" != "" ]         
        then                  
        echo $i >>outfile     
        echo $found >>outfile 
fi                            
done

In my case, I'm only looking in files which start with A-Z, but you can change that to suit your needs.

To run this script, change to the directory you want to search and enter:
# findstring 500-PROCESS-CREATE
Your results will be in "outfile".
 
PHV, man find does not give the answer I needed. I guess there is no way of doing this in the command line but to follow motoslide suggestion to create a script.

Thanks for the quick reply.
 
list all files in a directory that has the word "500-PROCESS-CREATE"
(cd /path/to/dir; fgrep -l "500-PROCESS-CREATE" *)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV, It works!! Thanks very much..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top