了解gnuplot如何使用awk脚本
我有一个数据文件
data.txt中 1 1 2 2 3 3 5 4 7 5 我试图了解gnuplot如何使用awk.我可以用情节“< awk'{print $1,$2}'data.txt”绘制它.但是,当我尝试加载'< ./ script.sh data.txt'时,它不起作用. script.sh #!/bin/bash awk 'BEGIN { printf "plot "; } { printf "%i %in",$1,$2 } ' $1 使用script.sh方法返回错误:
在我看来,我的awk脚本是内联awk语句的功能等价物.为什么script.sh方法不起作用? 仅供参考,我知道我可以用“data.txt”u 1:2来绘制我的数据.这只是我想要解决的更复杂问题的理想化版本. 解决方法
这应该与awk无关,但是对于plot和load命令都有gnuplots期望.
在我的理解中阅读gnuplot帮助输出并尝试您提供的示例: plot "<awk '{print $1,$2}' data.txt" 只是一种复杂的方式,通过popen调用在你的系统上提供一个像object这样的文件,plot命令然后从x,y点读取. 你的第二个脚本做了一些不同的事情,因为load命令现在在第一行接收一个它不能满足的命令(即绘图后跟一个x和y值),即使没有任何前缀命令也会收到后续命令(下一行只是2在这种情况下为2. 在我的活动gnuplot使用的记忆中 – 几年前,如果不是几十年;-) – 加载就像加载,你可以从模块组成绘图代码,但这些必须包含有效的gnuplot命令. 我系统上的加载帮助给出了: gnuplot> help load The `load` command executes each line of the specified input file as if it had been typed in interactively. Files created by the `save` command can later be `load`ed. Any text file containing valid commands can be created and then executed by the `load` command. Files being `load`ed may themselves contain `load` or `call` commands. See `comments` for information about comments in commands. To `load` with arguments,see `call`. Syntax: load "<input-file>" The name of the input file must be enclosed in quotes. The special filename "-" may be used to `load` commands from standard input. This allows a `gnuplot` command file to accept some commands from standard input. Please see help for `batch/interactive` for more details. On some systems which support a popen function (Unix),the load file can be read from a pipe by starting the file name with a '<'. Examples: load 'work.gnu' load "func.dat" load "< loadfile_generator.sh" The `load` command is performed implicitly on any file names given as arguments to `gnuplot`. These are loaded in the order specified,and then `gnuplot` exits. 我总是解决了生成匹配文件的问题,并为gnuplot调用提供了一些调用魔法来参数化这些图. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |