脚本与gnuplot的 - 在中美战略经济对话 [英] Scripting with gnuplot--where sed
问题描述
所以我在寻找一些快速和肮脏的解决方案。
So I'm looking for some quick-and-dirty solution.
问题:
我想用绘制的gnuplot数据文件的特定部分。这可以。基本路线是这样的东西。
I am trying to plot a specific section of a data file with gnuplot. This is fine. The basic line goes something like
plot "<(sed -n '1,100p' pointsandstuff.dat)" u 1:log($4**2+$5**2) notitle
这工作得很好。下一步我想在我的标题包括数据的另一部分,即数据条目$ 3(其中列出的点是相同的,所以我可以从任何地方它解析)。我碰到的问题,因为虽然剧情似乎罚款,我似乎无法养活正则表达式的信息为标题。该的东西的例子并不的作品
This works just fine. The next step I want is to include in my title another part of the data, namely the data entry $3 (which for the points listed is identical, so I can parse it from anywhere). I run into problem because, while plot seems fine, I can't seem to feed regex info into 'title'. An example of something that doesn't work"
plot "<(sed -n '1,100p' pointsandstuff.dat)" u 1:log($4**2+$5**2) title "<(sed -n '1,1p' pointsandstuff.dat)"
(这将吐出一个整体的数据线,在理论上,但实际上我刚拿到冠军&LT;(SED ...)
(This would spit out a whole data line, in theory, though in practice I just get the title "<(sed...")
我试着用一个bash脚本攻击这一点,但'$的,我用投掷bash脚本到迷惑不解:
I tried attacking this with a bash script, but the '$'s that I use throw the bash script into a tizzy:
#!/bin/bash
STRING=$(echo|sed -n '25001,25001p' pointsandstuff.dat)
echo $STRING
gnuplot -persist << EOF
set xrange[:] noreverse nowriteback
set yrange[:] noreverse nowriteback
eval "plot "<(sed -n '25001,30000p' pointsandstuff.dat)" u 1:log($4**2+$5**2) title $STRING
EOF
击不知道做什么用$ 4和5 $'做的。
Bash won't know what to do with '$4' and '$5'.
推荐答案
哈哈,谢谢大家。已经提出了几种方案现在 - 其中最简单的只从逃跑之前把这些$ S(我误以为gnuplot的不喜欢......)。为了白衣:
Aha, thanks all. Have come up with a few solutions by now--the simplest being just escaping those $s from before (which I mistakenly thought gnuplot disliked...). To whit:
STRING=$(echo|sed -n '1,1p' spointsandstuff.dat)
echo $STRING
gnuplot -persist << EOF
set xrange[:] noreverse nowriteback
set yrange[:] noreverse nowriteback
eval "plot "<(sed -n '1,100p' pointsandstuff.dat)" u 1:(log(\$4**2+\$5**2)) title '$STRING'
!gv diag_spec.eps &
EOF
感谢所有,虽然 - 它已经用这个东西玩的好借口......这里的希望,如果任何可怜的灵魂看到这个剧本后,它可能会在它们更容易一些。
Thanks all, though--it's been a good excuse to play with this stuff...here's hoping that, if any poor soul sees this script later, it might be a bit easier on them.
这篇关于脚本与gnuplot的 - 在中美战略经济对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!