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?

  • What shell are you using? Commented Jul 20, 2016 at 22:01
  • @StephenHarris C Shell. I know Bash is better, but can't I work on Csh?
    – Anonymous
    Commented Jul 20, 2016 at 22:02
  • 3
    What's the a// bit for? echo blah | sed 'a\\<NL>!' appends a ! without issue in csh... (where <NL> is a literal newline).
    – thrig
    Commented Jul 20, 2016 at 23:01
  • Possible duplicate of How to use a special character as a normal one? Commented Jul 21, 2016 at 16:28

1 Answer 1


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .