0

I would like to redirect output to a file how described in this StackOverflow question but with an exception: let's suppose I do not want to store all the lines which start with the character r.

Specifically, I execute:

./command | tee /tmp/output.txt

and I get all the printed lines in the file. How to modify the instruction to allow exception?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Leos313
  • 5,152
  • 6
  • 40
  • 69
  • 1
    Try: `./command | grep -v '^f' | tee /tmp/output.txt` – anubhava Jul 24 '20 at 16:45
  • that works perfectly. To conclude, I always use grep to build my own exception. Just answer to the question: it may be useful for someone else more – Leos313 Jul 24 '20 at 16:50

1 Answers1

2

This is a case for an output process substitution:

$ printf "%s\n" {o..u} | tee >(grep -v '^r' > outputfile)
o
p
q
r
s
t
u

$ cat outputfile
o
p
q
s
t
u
glenn jackman
  • 238,783
  • 38
  • 220
  • 352