3

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?

5 Answers 5

7

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

sed s/\!//g myfile
0
4

Try this:

$ sed s/\!//g myfile
4

Don't forget poor old tr

tr -d '!' < filename

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

2

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

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

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .