rascalofthenorth
rascalofthenorth

Reputation: 25

Search files for a string but exclude another string

I want to search files for \xc2 but exclude \xc2\xbb

I have grep -rnwl '/home/rascalofthenorth/development/html/' -e "xc2"

Upvotes: 0

Views: 54

Answers (1)

posixpascal
posixpascal

Reputation: 3140

You can also do it using -v option of grep like this:

grep -rnwl '/home/rascalofthenorth/development/html/' -e "xc2" | grep -v "xbb"

The -v option shows only results not containing xbb.

Or for more specific cases in which you want, say, xc2 to appear and xbb not to appear, then awk comes in handy:

awk '/xc2/ && !/xbb/' <yourfile>

Upvotes: 1

Related Questions