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
not sure what OS you are using, but grep -l (that's a lowercase L) will show just the filename, not the line that matches. Do a man on grep and it should tell you how to get just the name, or tell us the os and we might be able to help some more.