15

when i am trying to remove consecutive duplicate lines with

awk "!x[$0]++" file

its reporting x[: Event not found.

even the same case with

sed -i -e "$!N; /^\(.*\)\n\1$/!P;D" file as well reporting

N: Event not found. i tried with single quotes too, it didn't help

Any idea to fix those

user1228191
  • 681
  • 3
  • 10
  • 19

1 Answers1

27

You're invoking the shell's history substitution. Surround the exclamation point with single quotes.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Thanks so much, Working! when i tested this command in other system unix, it works correctly, what wrong with the shell! – user1228191 Apr 19 '12 at 05:10
  • one more thing when i tried to print `"Hello"` with `echo "\"Hello\"" ` in `tcsh` shellit saying `Unmatched ".` can you please fix this – user1228191 Apr 19 '12 at 05:21
  • 1
    Nope. Dunno tcsh, and I don't care to. – Ignacio Vazquez-Abrams Apr 19 '12 at 05:35
  • 3
    @user1228191: Once again, use single quotes: `echo '"Hello"'` – Dennis Williamson Apr 19 '12 at 07:25
  • I'm surprised that worked. In tcsh, `echo "'!'hello"` prints `'!'hello`, and `echo '!hello'` prints `hello: Event not found.`. It's generally more reliable to escape `!` characters with backslashes. (csh/tcsh syntax is not consistent and typically requires either trial and error or a different shell.) – Keith Thompson Dec 12 '17 at 00:53