Bookmark and Share

Using or matching backslash character ('\') correctly with grep or similar tools such as ack takes some investigation. Here is a note on what I found.

GNU grep

I created a text file temp.txt with

\
\\
\\\
\:0251

What I get from trying to match each line with grep (GNU bash 3.2.48) from Bash command line:

  • Use "\\\\" to match \

    $ grep -x --color=always "\\" temp.txt \

  • So to match \\, \\\\\\\\ is needed:

    $ grep -x --color=always "\\\\" temp.txt \

  • To Match \:0251 which is the Mathematica InputForm string of a Chinese character:

    $ grep -x --color=always "\\:0251" temp.txt :0251

Comments on this page are closed.
blog comments powered by Disqus