gnuplot - 如何在 gnuscript 中循环使用 grep 命令

标签 gnuplot

抱歉,我问了多个问题。 我有一个包含多个列的 case.dat 文件,我想根据 gnuscript 中的第 2 列提取数据数组。 我尝试使用下面的脚本,但它给了我错误

array=""
do for [i=300:800:100] {  # I mean start:end:increment. so it should read 300, 400, 500, 600, 700, 800 here
val ="grep i case.dat"        # Want to store the command in a valuel/variable
print val > i.dat              #Here I need to store the data in i.dat
}

错误

line 45: undefined variable: dat

我的 bash 脚本如下

##!/bin/bash
case="data"
for i in `seq 100 100 800`
do
       awk '$2=='$i'{print $0}' $case.dat > $i.dat
done

that I want to use at the start of the gnu-script so that the further operation can be done in the rest part of the gnu-script.

最佳答案

gnuplot 脚本:

do for [i=300:800:100] {
   outfile = sprintf("%d.dat", i)
   command = sprintf("grep %d case.dat",i)
   set print outfile
   print system(command)
   unset print
}

这将创建单独的文件 300.dat 400.dat 500.dat 等等。

如果您想将这些数据子集完全保留在 gnuplot 内部,即不创建任何新文件,您可以创建命名数据 block $data_300 $data_400 等:

do for [i=300:800:100] {
    eval( sprintf("set print $data_%3d", i) )
    print( sprintf("grep %d case.dat") )
    unset print
}

命名数据 block 通常可以在任何可以使用文件名的地方使用,例如 用线条绘制 $data_500

关于gnuplot - 如何在 gnuscript 中循环使用 grep 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58049022/

相关文章:

gnuplot - 超过 8 种颜色 gnuplot 的颜色序列

gnuplot:数据矩阵的 3D 图

linux - 用于时间线数据的类似 gnuplot 的程序

plot - 带背景颜色的盒装标签

gnuplot - 使用 gnuplot 获得平滑曲线

charts - Gnuplot 不绘制负值

statistics - gnuplot 统计范围可能吗?

gnuplot - 如何使用 gnuplot 获取径向(极坐标)图?

canvas - Gnuplot HTML Canvas 到具有缩放功能的静态页面

plot - GnuPlot 中的线图,其中线宽是我的数据文件中的第三列?