0

This question already has an answer here:

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 .02312
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 .02312
2L 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 .02312
3R 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 .02312
3R 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 .02312
X 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 .02312
X 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

File 2:

2R 201
3R 551
X 5342

What 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 .02312
3R 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 .02312
X 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

marked as duplicate by jasonwryan, don_crissti, polym, terdon Sep 24 '14 at 10:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

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 b

this would yield

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 .02312
3R 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 .02312
X 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.