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?


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

sed s/\!//g myfile

Try this:

$ sed s/\!//g myfile

Don't forget poor old tr

tr -d '!' < filename

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


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

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


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

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.