Search code examples
linuxgrepasciiextended-ascii

How to use grep command for count extended ASCII characters


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.


Solution

  • 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!