0

I have two tab-separated files:

File 1

123 456 135 567 234 478 

File 2

123 notimportant notimportant2 456 notimportant notimportant2 987 notimportant notimportant2 135 notimportant notimportant2 234 notimportant notimportant2 478 notimportant notimportant2 

I need to extract lines from file1 if both entries in a single row are present in file2's first column. So the output file should be like:

Output

123 456 234 478 

I previously used this awk command to extract rows if only the first column of file1 matched 1st column of file2

awk 'FNR==NR{a[$1];next}($1 in a){print}' file2 file1 

But I don't know how to expand it.

0

1 Answer 1

2
awk 'FNR==NR{a[$1]++;next;}($1 in a)&&($2 in a){print}' file2 file1 perl -lane ' @ARGV and $h{$F[0]}++,next; print if @F == grep { $h{$_} } @F; ' file2 file1 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.