Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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.
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.
grep
file1
file2
To avoid the results being displayed on the screen, you could say:
grep "some string" somefile | tee file1 > file2
Add a comment
You can also do it with awk
awk
awk '/some string/ {print | "tee file1"}' >file2 somefile
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.