7.5. Escaping the meaning of a special character using \

We may want to search for strings or characters they may sometimes contain a character that is considered a special character. What is a special character? For general purposes you may consider any of the following characters to be special characters

$." * [ ] ^ | () \ + ? 

Suppose we wanted to match any lines that had a period ‘ . ’ in them. We know a ‘ . ’ is a special character that lets you match any single character, so we need to disable this meaning. Here’s how we would do it:

\. 

The above says do not treat the character after the backslash as a special character, but treat it literally; in this case, treat it as a period.

Suppose we want to match any lines containing a caret ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.