Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a file that has a single line with a lot of ! characters. I want to remove all of the ! characters.

I tried this:

sed s/!// myfile

and this:

sed 's/!//' myfile

and this:

sed 's/"\!*"//' myfile

But they all just print out all of the "!".

I must be missing something obvious. Any ideas?

share|improve this question
up vote 7 down vote accepted

Add a g to your regexp, for global replacement. Otherwise, only the first occurrence will be substituted:

sed s/\!//g myfile
share|improve this answer
Thanks. I knew it was something simple like that. – Greg_the_Ant Mar 14 '12 at 19:05

Try this:

$ sed s/\!//g myfile
share|improve this answer

Don't forget poor old tr

tr -d '!' < filename

tr only operates on stdin, so you have to pipe data into it.

share|improve this answer

add the g at the end in order to replace all occurances.

sed 's/"!*"//g' myfile

share|improve this answer

You have to specify you want every occurence removed: sed 's/!//g' myfile
Note the g, which mean 'greedy'.
Without the 'g', you only have the first '!' removed

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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