Bash 如何在gnuplot中设置awk变量?
现在我可以像这样批量绘制Bash 如何在gnuplot中设置awk变量?,bash,variables,awk,gnuplot,batch-processing,Bash,Variables,Awk,Gnuplot,Batch Processing,现在我可以像这样批量绘制 filename(n) = sprintf("x0%.3fgammamax.txt", n) set term png size 800,600 enhanced do for [ii=0:10]{ tempi=(ii+0.0) outfile = sprintf('x0%.3fgammamax-pm3d.png',tempi) set output outfile splot filename(tempi) notitle with pm3d } 但是,现在我需要在
filename(n) = sprintf("x0%.3fgammamax.txt", n)
set term png size 800,600 enhanced
do for [ii=0:10]{
tempi=(ii+0.0)
outfile = sprintf('x0%.3fgammamax-pm3d.png',tempi)
set output outfile
splot filename(tempi) notitle with pm3d
}
但是,现在我需要在使用awk绘图之前处理数据。名为addblanks.awk的文件的内容为
/^[[:blank:]]*#/ {next} # ignore comments (lines starting with #)
NF < 3 {next} # ignore lines which don't have at least 3 columns
$1 != prev {printf "\n"; prev=$1} # print blank line
{print} # print the line
如果不需要动态文件名,请使用以下命令:
splot "<awk -f addblanks.awk data.txt" notitle with pm3d
然而,我需要动态文件名仍然使用awk现在。结果应该是:
splot "<awk -f addblanks.awk filename(tempi)" notitle with pm3d
如何使其工作?这可能会起作用:
splot "<awk -v TEMPI="$tempi" -f addblanks.awk filename(TEMPI)" notitle with pm3d
为了避免混淆,我用大写字母定义了awk变量。tempi=$tempi也应该可以工作。您只需使用以下命令连接两个字符串:
splot "<awk -f addblanks.awk ".filename(tempi) notitle with pm3d