user2503227
user2503227

Reputation: 137

Printing grep results to file and terminal

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

Answers (1)

faffaffaff
faffaffaff

Reputation: 3549

The program you are looking for is "tee":

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

Upvotes: 6

Related Questions