Off topic:match two columns from one file to three columns from another file, print out lines from the file with two columns
0
0
Entering edit mode
6.2 years ago
jingjin2203 ▴ 60

Hi All, I am new to awk, and having a hard time trying things myself, hope you can help me out. I have file A with two columns, it looks like this:

7000000185249034 1114

7000000185249048 1532690

7000000185249052 755361

7000000185249068 427550

7000000185249070 269102

7000000185249081 291122

And I have file B with three columns, it looks like this:

7000000185249100 1622651 1623044

7000000185249048 235104 235805

7000000185249146 2500324 2502635

7000000185249100 1218818 1221734

7000000185249468 88587 89699

7000000185249239 299691 300277

7000000185249315 769635 769986

7000000185249374 1548986 1549747

So what I wanted to do is to print out lines from file A, if the number in first column in file A matches the number in first column in file B, and the number in the second column in file A is within the range of the numbers in the second and third columns in file B.

I tried with the following code, but failed. awk -F '\t' 'FNR==NR{a[$1,$2,$3]=$0;next}{if(b=a[$1, >=$2 && <= $3]){print b}}' file B file A

Any advice will be appreciated! Thank you in advance!

awk grep linux • 831 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2550 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6