0

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

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

1 Answers1

1

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>

posixpascal
  • 3,031
  • 3
  • 25
  • 44
  • Thank you this has answered my question. I will accept the answer as soon as I am allowed to. Just one thing the | means pipe is that correct? So does this mean 'build a list of every file that has an "xc2" in it and then search that list and remove all the files that have an "xbb" in it? Or is something else going on? – rascalofthenorth Apr 11 '17 at 09:50
  • @rascalofthenorth Just to notice that using regexes could have hidden pitfalls . For example this solution will exclude `\xc2\xbb` but will also exclude `xc2xbb` , `xbbxc2`, \xbb\, and many other combinations in which xbb is part of . You might need a more complex regex not to wrongly exclude results that might be required to be returned. – George Vasiliou Apr 11 '17 at 10:00
  • Thank you George Vasiliou. Is it correct to say that "xc2" and "xbb" are little bits of regex in the second solution provided by Praszyk. for the first one would grep -rnwl '/home/rascalofthenorth/development/html/' -e "\xc2" | grep -v "\xc2\xbb" be more correct? – rascalofthenorth Apr 11 '17 at 10:39