Steven
Steven

Reputation: 2558

Stop grep from parsing its own output piped to file

I am using grep like this: grep -r "foo" * > output.txt

However it seems grep is constantly picking up results from output.txt which grows indefinitely. How can I prevent this from happening?

Upvotes: 0

Views: 34

Answers (2)

rurouni88
rurouni88

Reputation: 1173

See man grep. Then try this:

grep -r "foo" * --exclude=output.txt > output.txt

Upvotes: 2

Gilles Quénot
Gilles Quénot

Reputation: 185530

One solution is :

grep -r "foo" . > ../output.txt
                  ^^
            parent directory

Upvotes: 2

Related Questions