Reputation: 137
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
Upvotes: 3
Views: 3844
Reputation: 3549
The program you are looking for is "tee":
grep -n "$SEARCH_TERM" "$i" | tee -a /file.txt
Upvotes: 6