Reputation: 5451
I am able to search for a string(with some pattern) from a file using grep command manually. But using some script, I want to take a line(each line is a string) from a file1 which has say some 100 unique lines and search each string in a different file2 and if present, output the complete line from file2
file1
abcd
efgh
ijkl
mnop
file2
somestring abcd somestring
somestring somestring somestring
somestring ijkl somestring
somestring efgh somestring
Upvotes: 0
Views: 46
Reputation: 597
You can use:
egrep -f file_one file_two
or
grep -Ff file_one file_two
Upvotes: 1
Reputation: 786091
You can just use grep -Fwf
:
grep -Fwf file1 file2
-F ->
fixed string (no regex)-W ->
search for complete word-f <pattern-file> ->
take patterns from a fileUpvotes: 3