I have file1.txt
with content:
rs002
rs113
rs209
rs227
rs151
rs104
I have file2.txt
with content:
rs113 113
rs002 002
rs227 227
rs209 209
rs104 104
rs151 151
I want to get the lines of file2.txt
that match the records in file1.txt
, for which I tried:
grep -Fwf file1.txt file2.txt
with output as follows:
rs113 113
rs002 002
rs227 227
rs209 209
rs104 104
rs151 151
This extracts all the matching lines, but it is in the order of occurrence in file2.txt
. Is there any way to extract the matching records while maintaining the order from file1.txt
? The desired output is as follows:
rs002 002
rs113 113
rs209 209
rs227 227
rs151 151
rs104 104