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?

Sven
  • 98,649
  • 14
  • 180
  • 226
Greg_the_Ant
  • 489
  • 7
  • 26

5 Answers5

7

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

sed s/\!//g myfile
Sven
  • 98,649
  • 14
  • 180
  • 226
4

Try this:

$ sed s/\!//g myfile
jamzed
  • 1,070
  • 7
  • 8
4

Don't forget poor old tr

tr -d '!' < filename

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

glenn jackman
  • 4,630
  • 1
  • 17
  • 20
2

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

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

g24l
  • 146
  • 4
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

Gregory MOUSSAT
  • 1,673
  • 2
  • 25
  • 50