So while helping someone debug some code I realized that there were some weird characters in their output, namely � and �(\xc0 and \xd0 in hex).
I wanted to find these characters in a large text output file.
I've managed to locate these characters using sublime by enabling the regex option in find with \xc0
or \xd0
being the query. I have also managed to grep
them by doing grep $'\xc0' filename
in bash.
The thing that is bothering me right now is that, if I use the -P
option for grep
, it refuses to find these characters.
grep -P "\xc0" filename
would print out nothing for a file that has that character in it(and the other two methods above would successfully find it), and this is bugging me so badly I want to know why this wouldn't work.
I have read a couple of other posts in which the -P
option along with "[\x80-\xff]"
are suggested but for some reason I just couldn't get them to work :\
grep -P
has been a good friend for a long time until now :( Any help and tips are appreciated!
I'm using GNU grep.
EDIT:
I have actually tried on 2 linux distributions.
- On Ubuntu 14.04 with bash: My terminal doesn't seem to like the character :\
printf "\xc0"
prints out nothing in the terminal, however printing it to a file with >
and then opening in sublime would show the character.
printf "\xc0" > foo
grep $'\xc0' foo > out1
grep -P '\xc0' foo > out2
grep -P '\x{c0}' foo > out3
out{1,2,3}
are all empty.
- On CentOS 7.2 with bash:
printf
prints something - the question mark dark thingy
printf "\xc0"
prints out �(actually looks like this)
printf "\xc0" > foo
grep $'\xc0' foo > out1
grep -P '\xc0' foo > out2
grep -P '\x{c0}' foo > out3
Only out1
contains the character.