How to use grep command for count extended ASCII characters

593 views Asked by At

I have a file which contains Inverted exclamation mark, I want to count number of occurrences of these inverted exclamation marks using Linux grep command.

I have tried hex representation of this character as follows. but it is returning complete file , not exactly the lines which are matching this text.

grep -v "["$'\xA1'"]" K2345061.005 

Thanks in advance for sharing any idea on this issue.

2

There are 2 answers

0
Tim Pierce On BEST ANSWER

If your grep supports the -P flag for PCRE regex syntax, you can use that:

$ echo -e '\xa1Ay caramba!' > /tmp/a1.dat
$ grep -P '\xa1' /tmp/a1.dat 
¡Ay caramba!
1
Robin Green On

grep -v is used to list files which do not match. Remove the -v option.