抱歉,我问了多个问题。 我有一个包含多个列的 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/