I apologize in advance, but I continue to have trouble searching for matches between two files and then printing portions of each to output in [g]awk and would very much appreciate some help.
I have data as follows:
File1
PS012,002 PRQ 0 1 1 17 1 0 -1 3 2 1 2 -1 1 1 -1 -1 -1 -1 0 501 0
PS012,002 MRJ> 0 3 -1 -1 -1 1 -1 -1 -1 0 0 2 3 3 2 -1 -1 -1 0 562 0
PS012,002 MVL 0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS012,002 D -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0
PS012,002 GMR 0 1 0 17 1 0 -1 2 3 1 2 -1 1 1 -1 -1 -1 -1 0 501 0
PS012,002 VB 0 13 -1 -1 -1 1 -1 -1 -1 0 0 3 2 2 2 -1 -1 -1 0 502 0
PS012,002 W 0 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0
PS012,002 BVL 0 1 0 17 12 0 -1 2 3 1 1 -1 1 1 -1 -1 -1 -1 0 501 0
PS012,002 HJMNW 0 2 -1 -1 -1 11 -1 -1 -1 1 1 3 2 2 2 -1 -1 -1 0 502 0
PS012,002 MN 0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS012,002 >R< 0 2 -1 -1 -1 1 -1 -1 -1 0 1 3 2 5 2 -1 -1 -1 0 505 0
File2
008 PS012,001 CMJNJ 008 ?
010 PS012,001 MZMWR 010 ?
011 PS012,001 L 011 ?
012 PS012,001 DWD 012 ?
014 PS012,002 JC< 014 PRQ
016 PS012,002 JHWH 016 MRJ>
018 PS012,002 ? 018 MVL
019 PS012,002 KJ 019 D
020 PS012,002 GMR 020 GMR
021 PS012,002 XSJD 021 VB
023 PS012,002 KJ 023 W
024 PS012,002 PSS 024 BVL
025 PS012,002 >MWN 025 HJMNW
026 PS012,002 MN 026 MN
027 PS012,002 BN 027 >R<
028 PS012,002 >DM 028 ?
If $2 and $5 of File2 match $1 and $2 of File1, I would like to print $4 of File2 followed by $0 of File1.
Intended Output:
014 PS012,002 PRQ 0 1 1 17 1 0 -1 3 2 1 2 -1 1 1 -1 -1 -1 -1 0 501 0
016 PS012,002 MRJ> 0 3 -1 -1 -1 1 -1 -1 -1 0 0 2 3 3 2 -1 -1 -1 0 562 0
018 PS012,002 MVL 0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
019 PS012,002 D -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0
020 PS012,002 GMR 0 1 0 17 1 0 -1 2 3 1 2 -1 1 1 -1 -1 -1 -1 0 501 0
021 PS012,002 VB 0 13 -1 -1 -1 1 -1 -1 -1 0 0 3 2 2 2 -1 -1 -1 0 502 0
023 PS012,002 W 0 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0
024 PS012,002 BVL 0 1 0 17 12 0 -1 2 3 1 1 -1 1 1 -1 -1 -1 -1 0 501 0
025 PS012,002 HJMNW 0 2 -1 -1 -1 11 -1 -1 -1 1 1 3 2 2 2 -1 -1 -1 0 502 0
026 PS012,002 MN 0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
027 PS012,002 >R< 0 2 -1 -1 -1 1 -1 -1 -1 0 1 3 2 5 2 -1 -1 -1 0 505 0
I have been attempting the following code to no avail.
awk 'NR==FNR {q=$1 SUBSEP $2; A[q]=$0; next} ($2,$5) in A{print $0,A[$1,$2]}' file1 file2