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

编程入门 行业动态 更新时间:2024-10-28 19:34:26
本文介绍了如何在gnuscript中的循环中使用grep命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对不起,我要问多个问题. 我有一个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命令

本文发布于:2023-10-04 21:33:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   如何在   gnuscript   grep

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!