I have file1.txtwith content:
rs002
rs113
rs209
rs227
rs151
rs104
I have file2.txtwith content:
rs113 113
rs002 002
rs227 227
rs209 209
rs104 104
rs151 151
I want to get strings file2.txtthat match the entries in file1.txtfor which I tried:
grep -Fwf file1.txt file2.txt
with the output as follows:
rs113 113
rs002 002
rs227 227
rs209 209
rs104 104
rs151 151
This retrieves all matching rows, but is in order of appearance in file2.txt. Is there a way to retrieve matching records while maintaining order s file1.txt? The required output is as follows:
rs002 002
rs113 113
rs209 209
rs227 227
rs151 151
rs104 104
source
share