Reputation: 75
Hi I'm new to this forum. Pls forgive me if I did not follow forum standard. I have a file with below data
searchSTR.txt :
abc123
bac234
ret235
now I want to search each string from searchSTR.txt in all files in my directory I'm expecting below format of output
abc123 inventory.txt
bac234 names.txt
(here abc123 search string found in invertory.txt file bac234 search string found in names.txt file)
please provide me solution using grep or awk Thanks
Upvotes: 0
Views: 907
Reputation: 786289
Why not give grep -o -f
a try like this:
grep -o -f searchSTR.txt *sh
Upvotes: 3
Reputation: 185851
Try this :
while read w; do
for f in *; do
grep -q "$w" "$f" && echo "$w $f"
done
done < searchSTR.txt
Upvotes: 1