我是 unix 编程的初学者,并且是一种自动化工作的方法
我想运行一个 list a grep 命令,并在单个分隔文件中获取所有 grep 命令的输出。
我正在使用以下 bash 脚本。但它不起作用。
样机sh文件:
!/bin/sh
grep -l abcd123
grep -l abcd124
grep -l abcd125
在运行时我使用了以下命令
$ ./Mockup.sh > output.txt
这是正确的命令吗?
如何在输出文件中同时获得 grep 命令和输出?
如何在每个命令和结果后分隔输出?
最佳答案
How can I get both the grep command and output in the output file
您可以使用 bash -v
(详细)在 stderr
上在执行前打印每个命令,它的输出将像往常一样可用在 stdout
上:
bash -v ./Mockup.sh > output.txt 2>&1
cat output.txt
Working Demo
关于linux - UNIX shell 脚本,用于从文件运行 grep 命令列表并在单个分隔文件中获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26757667/