The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-19-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
grep string and output filename

Hello,

I have over 200 files and some of them have the string like "John price $200". I would like to grep the string. Then output the filename which found the string.

I have the following script, but it ONLY output the string
echo Please input list file name:
read listn
for file in `cat $listn.txt`
do
cat $file |grep "John price $200"
done

expect output:
filename: XXXXXX
found string: John price $200


thx,
happyv