我正在使用以下行
awk '{if (FNR==90307) for(i=2;i<=10;i+=3) print " x=", x=$i," y=", y=$(i+1), "z=", z=$(i+2) }' coord.xvg veloc.xvg force.xvg
此脚本从每个文件xvg输出xyz。
x= 5.78201 y= 6.72302 z= 7.07345
x= 5.81603 y= 6.76299 z= 6.94258
x= 5.70397 y= 6.75502 z= 6.85738
x= -3.29165e-05 y= -3.86794e-05 z= 0.000126634
x= -1.77439e-05 y= 3.28865e-05 z= -0.000156011
x= -1.52779e-05 y= -9.56992e-05 z= 0.000427172
x= 6.30622 y= 86.4321 z= 51.1683
x= 55.7424 y= 26.0566 z= 76.0063
x= -459.011 y= 19.386 z= 302.62
问题是在同一个do-loop(当前帧)中,我可以进行以下乘法
i=2
(x(2) from force.xvg) X (y(2) from coord.xvg)
i=3
(x(3) from force.xvg) X (y(3) from coord.xvg)
i=4
... .. ...。 ...
答案 0 :(得分:1)
无法测试:
awk '
FNR == 90307 {
for (n=2; n<=10; n+=3) {
i=(n+1)/3
x[i,FILENAME] = $n
y[i,FILENAME] = $(n+1)
z[i,FILENAME] = $(n+2)
print FILENAME, i, " x=", $n," y=", $(n+1), "z=", $(n+2)
}
}
END {
print "the products:"
for (i=1; i<=3; i++) {
print i, x[i,"force.xvg"] * y[i,"coord.xvg"]
}
}
' coord.xvg veloc.xvg force.xvg
关键点在这里:
FILENAME
是一个包含当前输入文件名称的awk变量i
和FILENAME
与SUBSEP
变量连接)