How to use ! in the sed command?

Anonymous

Apologize if you feel this question very basic. Anyways, I am typing
sed '/[iI]t/ a\\ Found it!' data but it says the error event not found.

I tried escaping that ! with backslash \! but it doesn't work.

I don't understand when backslash \ can escape a character and use it literally then why doesn't it work in sed?

chukko

Which OS did you try it on? On HP-UX 8.11 csh there are 2 ways to cancel the speacial meaning of exclamation mark for history substitutions (see History substitutions in man csh).

  1. Put space after ! (couple of other characters work too)

    sed '/[iI]t/ a\\
    Found it! ' data
    
  2. Escape it via \!

    sed '/[iI]t/ a\\
    Found it\!' data
    

    This actually also works with double quotes:

    sed "/[iI]t/ a\\
    Found it\!" data
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related