I have file.txt with names one per line as shown below:
ABCB8
ABCC12
ABCC3
ABCC4
AHR
ALDH4A1
ALDH5A1
....
I want to grep each of these from an input.txt file.
Manually i do this one at a time as
grep "ABCB8" input.txt > output.txt
Could someone help to automatically grep all the strings in file.txt from input.txt and write it to output.txt.
Contents of
text.txt
:Edit:
A safer solution with while read:
Edit 2:
Sample
text.txt
:Sample
input.txt
:If You don't care about the order of lines, the quick workaround would be to pipe the solution through a
sort | uniq
:The result is then in
output.txt
.Edit 3:
Is that fine?
You can use the
-f
flag as described in Bash, Linux, Need to remove lines from one file based on matching content from another fileFlag
-f FILE
,--file=FILE
:-o
,--only-matching
: