Remove lines containing strings from a file

Experts Hi,

I wish to remove lines containing the following strings from a file hello.out and save it in new_hello.out file.

1. text4
2. text5
3. text11
4. file13
5. file15
6. text16

The below works however, is it possible to club all the grep -v into a single grep -v ?

cat hello.out | grep -v text4 | grep -v text5 | grep -v text11 | grep -v text16 | grep -v file13 | grep -v file15 > new_hello.out

I'm aware of of using grep -E and clubbing multiple strings however I'm not sure of grep -v

I'm on Redhat Linux 7.

Have you tried running the grep -E -v "string1|string2" and observe the results ?

Regards
Peasant.

1 Like

No -E necessary:

$ cat file
text4
text5
text11
file13
file15
text16

$ echo {text,file}{4..16}$'\n' | grep -vffile
 

EDIT: or, try

grep -v -etext4 -etext5 -etext11 -efile13 -efile15 -efile16