There is file1.txt with the following contents:
H aa 0 0 1 -9
H bb 0 0 2 -9
H cc 0 0 2 -9
There is file2.txt with the following contents:
H aa 0 0 0 -9 asd qwe
H bb 0 0 0 -9 fgh rty
H cc 0 0 0 -9 jkl uio
Now I want to merge files according to the same column characters of file1 and file2. The requirements are as follows: 1. If the second column of the two files is the same, then modify the third, fourth, fifth and sixth columns of file2 to file1 Corresponding contents of the third, fourth, fifth and sixth columns; 2. The seventh and eighth columns of the new file are the seventh and eighth columns of file2.
The content of the merged file file3.txt is as follows:
H aa 0 0 1 -9 asd qwe
H bb 0 0 2 -9 fgh rty
H cc 0 0 2 -9 jkl uio
The command used is:
awk 'NR==FNR{a[$2]=$0;next}NR>FNR{if($2 in a)print a[$1],a[$2],$7,$8}' file1.txt file2.txt > file3.txt