我想要这样的东西:
file1='logs/last/mydata1.log'
file2='logs/last/mydata2.log'
# declare function that uses awk to reshape the data - does not work :(
sum1(fname)=("<awk '{sum=0; for(i=8;i<=NF;i+=2) sum+=$i; print $1,sum/2}' $fname")
sum2(fname)=("<awk '{sum=0; for(i=9;i<=NF;i+=2) sum+=$i; print $1,sum/2}' $fname")
# plot different columns of my file and awk processed file
plot file1 u 1:2 title "thing A measure 1" w l, \
file1 u 3:4 title "thing A measure 2" w l, \
file2 u 1:2 title "thing B measure 1" w l, \
file2 u 3:4 title "thing B measure 2" w l, \
sum1(file1) u 1:2 title "group A measure 1" w l, \
sum2(file1) u 1:2 title "group A measure 2" w l, \
sum1(file2) u 1:2 title "group B measure 1" w l, \
sum2(file2) u 1:2 title "group B measure 2" w l
不工作的是awk
gnuplot 函数内部的部分。工作正常后直接使用我的awk
脚本plot
:
plot "<awk '{sum=0; for(i=9;i<=NF;i+=2) sum+=$i; print $1,sum}' ./logs/last/mydata1.log" u 1:2 w l
有没有办法awk
在 gnuplot 函数中放置或其他 shell 命令?我知道我可以将 awk 脚本外包给另一个文件,然后直接 awk 这个文件plot
,但我不想要单独的文件。