本文介绍了将 grep 结果打印到文件和终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向终端和文件显示 grep 结果.我想出的解决方案是只运行两次,但这显然会产生效率问题.
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?
谢谢
推荐答案
您要找的程序是tee":
The program you are looking for is "tee":
grep -n "$SEARCH_TERM" "$i" | tee -a /file.txt
这篇关于将 grep 结果打印到文件和终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!