3

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?

3

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
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.