对不起,我要问多个问题. 我有一个case.dat文件,其中有多个列,我想根据文本中的第2列提取数据数组. 我尝试使用以下脚本,但这给了我错误
sorry, I am asking multiple questions. I have a case.dat file which is having multiple columns and I want to extract array of the data according to colum 2 in the gnuscript. I tried with below script but it is giving me error
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脚本如下所示
my bash script is like below
##!/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脚本:
gnuplot script:
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等等.
This will create separate files 300.dat 400.dat 500.dat and so on.
如果您想将这些数据子集完全保留在gnuplot内部,即不创建任何新文件,则可以创建命名数据块$ data_300 $ data_400等:
If you want to keep these data subsets entirely internal to gnuplot, i.e. not create any new files, you could instead create named datablocks $data_300 $data_400 etc:
do for [i=300:800:100] { eval( sprintf("set print $data_%3d", i) ) print( sprintf("grep %d case.dat") ) unset print }命名数据块通常可以在任何可以使用文件名的位置使用,例如 plot $data_500 with lines.
Named datablocks can in general be used anywhere you could use a file name, e.g. plot $data_500 with lines.
更多推荐
如何在gnuscript中的循环中使用grep命令
发布评论