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

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

问题描述

我是 Unix 编程的初学者,并且是一种自动化工作的方法
我想运行一个 grep 命令列表,并在单个分隔文件中获取所有 grep 命令的输出.

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 .

我正在使用以下 bash 脚本.但它不起作用.

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

样机sh文件:

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

在运行时我使用了以下命令

and while running i used the following command

$ ./Mockup.sh > output.txt

这是正确的命令吗?

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

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?

推荐答案

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

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

您可以使用 bash -v(详细)在 stderr在执行前打印每个命令,它的输出将照常可用在 stdout 上:

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

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

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