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

0

1 Answer 1

28

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks so much, Working! when i tested this command in other system unix, it works correctly, what wrong with the shell!
one more thing when i tried to print "Hello" with echo "\"Hello\"" in tcsh shellit saying Unmatched ". can you please fix this
Nope. Dunno tcsh, and I don't care to.
@user1228191: Once again, use single quotes: echo '"Hello"'
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.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.