UNIX shell脚本运行从文件在一个单一的分隔文件的grep命令的列表,并获得结果 [英] UNIX shell script to run a list of grep commands from a file and getting result in a single delimited file

查看:157
本文介绍了UNIX shell脚本运行从文件在一个单一的分隔文件的grep命令的列表,并获得结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UNIX编程初学者,一种方法可以自动我的工作结果
我想运行列表中的grep命令并得到所有的grep命令的输出在单个分隔的文件。

我用下面的bash脚本。但它不工作。

样机SH文件:

 !/ bin / sh的
grep的-l abcd123
grep的-l abcd124
grep的-l abcd125

和运行时我用下面的命令

  $ ./Mockup.sh> output.txt的

是不是正确的命令?

如何在输出文件中同时获得grep命令和输出?

如何划定输出每个命令后的结果?


解决方案

  

我怎样才能在输出文件中同时获得grep命令和输出


您可以使用庆典-v (详细)为打印每个命令执行前标准错误和它的输出将照常提供对标准输出

 的bash -v ./Mockup.sh> output.txt的2  - ;&放大器; 1猫output.txt的

工作演示

I am beginner in unix programming and a way to automate my work
I want to run a list a grep commands and get the output of all the grep command in a in a single delimited file .

i am using the following bash script. But it's not working .

Mockup sh file:

!/bin/sh
grep -l abcd123
grep -l abcd124
grep -l abcd125

and while running i used the following command

$ ./Mockup.sh > output.txt

Is it the right command?

How can I get both the grep command and output in the output file?

how can i delimit the output after each command and result?

解决方案

How can I get both the grep command and output in the output file

You can use bash -v (verbose) to print each command before execution on stderr and it's output will be as usual be available on stdout:

bash -v ./Mockup.sh > output.txt 2>&1

cat output.txt

Working Demo

这篇关于UNIX shell脚本运行从文件在一个单一的分隔文件的grep命令的列表,并获得结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆