如何在Gnuplot中运行Shell命令并将输出放置在新文件中

时间:2018-11-28 12:53:59

标签: gnuplot

我有以下Gnuplot:

set encoding iso_8859_1
set key right bottom #font "Helvetica,17" 
set ylabel "Lookup error probability" font "Helvetica,17"
set xlabel "Hight of the reader (m)" font "Helvetica,17"
set xtics font "Helvetica,15"
set ytics font "Helvetica,15"
set size 0.75, 1.05
set terminal postscript eps enhanced color #"Helvetica" 16 #size 3.5in,3in
set grid 
set key spacing 1.5

set output "ProbError6x6.eps"
list(start,end,increment)=system(sprintf("seq %g %g %g", start, increment, end))

system("(awk '(NR>8 ){print; }' Hight_6x6.csv | sed -e 's/[",]/ /g' | sort -nk36) > pe_H_6x6.txt")

set print "pe_H_6x6.dat"
do for [i in list(2,3.5,0.25) ] {
  stats "pe_H_6x6.txt" u ($36==i?($37/$38):1/0) name "A" nooutput
  print i*1, A_mean,   (A_mean - 1.833*A_ssd/sqrt(A_records)),\
    (A_mean + 1.833*A_ssd/sqrt(A_records))
}
plot [][] "pe_H_6x6.dat" using 1:2:3:4 with yerrorlines ls 2 title "6x6 blocks"

在我的Gnuplot脚本中,带有system和带有awk代码的行不起作用。但是,它可以在unix shell中使用。该代码删除逗号和,中的Hight_6x6.csv,跳过前8行,并按第36列的值对结果进行排序。 我无法使其在Gnuplot脚本中工作。 CSV文件位于此link中。

1 个答案:

答案 0 :(得分:2)

您的问题可能是在命令中包含双引号:

system("(awk '(NR>8 ){print; }' Hight_6x6.csv | sed -e 's/[",]/ /g' | sort -nk36) > pe_H_6x6.txt"
                                                           ^

一种解决方法是使用反引号,例如:

`(awk '(NR>8 ){print; }' Hight_6x6.csv | sed -e 's/[",]/ /g' | sort -nk36 > pe_H_6x6.txt`

或者就像我写的那样:

`tail -n+8 Hight_6x6.csv | tr '",' ' ' | sort -nk36 > pe_H_6x6.txt`