January 14, 2020

Exclude a word with grep

Exclude a word with grep

Grep a file for everything but a word

To exclude a single word:

the following will print everything but lines containing "excludedword"

grep -v excludedword

The following is a working example of pipeing to grep and exluding each line with the ip address 1.1.1.1:

sudo tcpdump | grep -v 1.1.1.1

To Exclude multiple words:

grep -v -e word1 -e word2

Piping to grep example:

sudo tcpdump | grep -v -e 1.1.1.1 -e 2.2.2.2

or on a text file:

grep -v -e 1.1.1.1 -e 2.2.2.2 iplist.txt