Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

5 Answers

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
add comment

Try this:

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

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 comment

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

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.