O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required