Printing grep results to file and terminal

心已入冬 提交于 2019-12-20 02:48:24

问题


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


回答1:


The program you are looking for is "tee":

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


来源:https://stackoverflow.com/questions/17203050/printing-grep-results-to-file-and-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!