代码之家  ›  专栏  ›  技术社区  ›  leaRner

如何保存bash输出中以文件中特定单词开头的文本?[副本]

  •  0
  • leaRner  · 技术社区  · 7 年前

    我正在使用Debian Linux(BeagleBone黑色)。我使用的程序在屏幕上打印了很多信息。到目前为止,我一直在将整个输出保存在一个文本文件中,这显然占用了有限存储空间的很大一部分。例如,我在做这样的事情:

    ./exampleProgram > Output.txt
    

    ./exampleProgram | grep "Schedule request" > Output.txt
    

    我该怎么做?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Charles Duffy    7 年前

    在现代GNU平台上:

    stdbuf -oL ./exampleProgram \
      | grep --line-buffered "Schedule request" \
      > Output.txt
    
    • stdbuf -oL exampleProgram 示例程序 可以覆盖或忽略此设置,因此其实现很重要)。
    • grep --line-buffered