I currently have two files that look something like this:File 1:2R 101 1:0:0:14:0:0 0:1:0:34:0:0 0:3:0:62:0:0 0:0:0:11:0:0 .023122R 201 0:2:0:24:0:0 0:0:0:44:0:0 0:0:0:15:0:0 0:0:0:22:0:0 .023122L 301 0:4:0:24:0:0 0:0:0:61:0:0 0:0:0:17:0:0 0:0:0:54:2:0 .023123R 551 0:2:0:64:0:1 0:1:0:67:0:0 0:0:0:22:0:0 0:0:0:31:1:0 .023123R 651 0:2:0:64:0:1 0:1:0:67:0:0 0:0:0:22:0:0 0:0:0:31:1:0 .02312X 1312 0:0:3:24:0:0 0:5:0:65:0:0 0:0:0:55:0:0 0:0:0:14:0:0 .02312X 5342 0:0:3:24:0:0 0:5:0:65:0:0 0:0:0:55:0:0 0:0:0:14:0:0 .02312File 2:2R 2013R 551X 5342What I would like to do is extract all the rows from File 1 where the entries for the first two columns match rows in File 2. So, based on this example, I would want my output file to look like:Output File:2R 201 0:2:0:24:0:0 0:0:0:44:0:0 0:0:0:15:0:0 0:0:0:22:0:0 .023123R 551 0:2:0:64:0:1 0:1:0:67:0:0 0:0:0:22:0:0 0:0:0:31:1:0 .02312X 5342 0:0:3:24:0:0 0:5:0:65:0:0 0:0:0:55:0:0 0:0:0:14:0:0 .02312
Extracting lines from a file based on two columns in another text file
linux
let's suppose file 2 is A and datafile (file 1) is b awk 'FILENAME == A { remember[$1 $2]=1 ;} FILENAME != A { if ( $1 $2 in remember ) print ; } ' A bthis would yield2R 201 0:2:0:24:0:0 0:0:0:44:0:0 0:0:0:15:0:0 0:0:0:22:0:0 .023123R 551 0:2:0:64:0:1 0:1:0:67:0:0 0:0:0:22:0:0 0:0:0:31:1:0 .02312X 5342 0:0:3:24:0:0 0:5:0:65:0:0 0:0:0:55:0:0 0:0:0:14:0:0 .02312