两个文件的对应列相减
cat file1
ATOM 1 N ASP 1 104.872 46.138 60.493 1.00 0.00 N
ATOM 2 H1 ASP 1 105.169 46.143 60.702 1.00 0.00 H
ATOM 3 H2 ASP 1 105.241 46.250 60.447 1.00 0.00 H
ATOM 4 H3 ASP 1 105.174 45.965 60.473 1.00 0.00 H
ATOM 5 CA ASP 1 103.501 46.223 60.288 1.00 0.00 C
cat file2
ATOM 1 N ASP 1 104.307 46.895 65.756 1.00 0.00 N
ATOM 2 H1 ASP 1 104.961 47.329 65.120 1.00 0.00 H
ATOM 3 H2 ASP 1 104.636 45.956 65.926 1.00 0.00 H
ATOM 4 H3 ASP 1 104.324 47.367 66.649 1.00 0.00 H
ATOM 5 CA ASP 1 102.945 46.927 65.177 1.00 0.00 C
awk -vOFS='\t' 'NR==FNR{for(i=5;i++<NF;)a[FNR,i]=$i;next}{for(i=;i++<NF;)$i=$i-a[FNR,i]}2' file1 file2
得到的结果是后3列也被减掉
ATOM 1 N ASP 1 0.565 -0.757 -5.263 0 0 0
ATOM 2 H1 ASP 1 0.208 -1.186 -4.418 0 0 0
ATOM 3 H2 ASP 1 0.605 0.294 -5.479 0 0 0
ATOM 4 H3 ASP 1 0.85 -1.402 -6.176 0 0 0
ATOM 5 CA ASP 1 0.556 -0.704 -4.889 0 0 0
我希望的结果是
ATOM 1 N ASP 1 0.565 -0.757 -5.263 1.00 0.00 N
ATOM 2 H1 ASP 1 0.208 -1.186 -4.418 1.00 0.00 N
ATOM 3 H2 ASP 1 0.605 0.294 -5.479 1.00 0.00 N
ATOM 4 H3 ASP 1 0.85 -1.402 -6.176 1.00 0.00 N
ATOM 5 CA ASP 1 0.556 -0.704 -4.889 1.00 0.00 N
ATOM 1 N ASP 0 0.565 -0.757 -5.263 1.00 0.00 N
ATOM 2 H1 ASP 0 0.208 -1.186 -4.418 1.00 0.00 H
ATOM 3 H2 ASP 0 0.605 0.294 -5.479 1.00 0.00 H
ATOM 4 H3 ASP 0 0.85 -1.402 -6.176 1.00 0.00 H
ATOM 5 CA ASP 0 0.556 -0.704 -4.889 1.00 0.00 C