本文介绍了将grep结果打印到文件和终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将grep结果显示给终端以及一个文件。我提出的解决方案是只运行两次,但这显然会造成效率问题。

  grep -n $ SEARCH_TERM$ i
grep -n$ SEARCH_TERM$ i>> /file.txt

是否有一个标签可以仅使用一次搜索打印?

谢谢 解决方案

您正在寻找的程序是tee :

  grep -n$ SEARCH_TERM$ i| tee -a /file.txt 


I'm trying to display the grep results to the terminal as well as to a file. The solution I've come up with is to just run it twice, but this obviously will create efficiency issues.

grep -n "$SEARCH_TERM" "$i"
grep -n "$SEARCH_TERM" "$i" >> /file.txt

Is there a tag that will allow it to print to both using only one search?

Thanks

解决方案

The program you are looking for is "tee":

grep -n "$SEARCH_TERM" "$i" | tee -a /file.txt

这篇关于将grep结果打印到文件和终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:32