Reputation: 3397
I want to create a file with the output of a grep search but in a folder included in the search. If I do:
grep -rnw . -e "text" > test/files.txt
It never ends because it always add one more files.txt. How can I do it after it finishes?
grep -rnw . -e "text" >| test/files.txt
This gives the same output than the previous one. Any idea?
Upvotes: 2
Views: 148
Reputation: 16507
Also you can try this:
cat <<< "$(grep -rnw . -e "text")" > test/files.txt
Upvotes: 0
Reputation: 37365
Use parent directory:
grep -rnw . -e "text" > ../files.txt && mv ../files.txt test/files.txt
This, however, relies on relative path which may fail in some contexts. Use static independent path (for example, /tmp
) to avoid that.
Upvotes: 1