user3044691
user3044691

Reputation: 69

Unix : Grep output to multiple files

I want to grep the same output to multiple files. example : grep "some string" > file 1 and file 2, i want this. Can anyone help me? Thanks in Advance.

Upvotes: 0

Views: 854

Answers (2)

Jotne
Jotne

Reputation: 41456

You can also do it with awk

awk '/some string/ {print | "tee file1"}' >file2 somefile

Upvotes: 0

devnull
devnull

Reputation: 123508

You can say:

grep "some string" somefile | tee file1 | tee file2

This would redirect the result of grep to file1 and file2 and also display that on screen.

To avoid the results being displayed on the screen, you could say:

grep "some string" somefile | tee file1 > file2

Upvotes: 1

Related Questions