问题
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