如何保存 bash 输出中以文件中特定单词开头的文本?
How can I save text from bash output which starts with a specific word in a file?
我正在使用 Debian Linux(在 BeagleBone Black 中)。我正在使用的程序在屏幕上打印了很多信息。到目前为止,我一直将整个输出保存在一个文本文件中,这显然占用了有限存储空间的很大一部分 space。例如,我正在做这样的事情:
./exampleProgram > Output.txt
正如我所说,此文件包含很多信息,目前我并不真正需要这些信息。我只关心以 "Schedule request" 开头的行。我正在寻找一种方法将这些行保存到输出文件,而忽略其余部分。我试过跟随,但没有成功。
./exampleProgram | grep "Schedule request" > Output.txt
我该怎么做?
在现代 GNU 平台上:
stdbuf -oL ./exampleProgram \
| grep --line-buffered "Schedule request" \
> Output.txt
stdbuf -oL
是一个 GNU 工具,它将标准输出配置为在 运行 exampleProgram
之前无缓冲。 (exampleProgram
可以覆盖或忽略此设置,因此它的实现很重要)。
grep --line-buffered
告诉 GNU grep 不要缓冲大于一行的部分。
我正在使用 Debian Linux(在 BeagleBone Black 中)。我正在使用的程序在屏幕上打印了很多信息。到目前为止,我一直将整个输出保存在一个文本文件中,这显然占用了有限存储空间的很大一部分 space。例如,我正在做这样的事情:
./exampleProgram > Output.txt
正如我所说,此文件包含很多信息,目前我并不真正需要这些信息。我只关心以 "Schedule request" 开头的行。我正在寻找一种方法将这些行保存到输出文件,而忽略其余部分。我试过跟随,但没有成功。
./exampleProgram | grep "Schedule request" > Output.txt
我该怎么做?
在现代 GNU 平台上:
stdbuf -oL ./exampleProgram \
| grep --line-buffered "Schedule request" \
> Output.txt
stdbuf -oL
是一个 GNU 工具,它将标准输出配置为在 运行exampleProgram
之前无缓冲。 (exampleProgram
可以覆盖或忽略此设置,因此它的实现很重要)。grep --line-buffered
告诉 GNU grep 不要缓冲大于一行的部分。