-1

Before this question is marked as a duplicate let me explain. I'm trying to remove the following string occurrences from a file:

 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)

i've looked at similar questions and they suggest the usage of the sed command:

sed -i -e 's/removedString//g' filename

The problem is that when I execute the above command with the string:

sed -i -e 's/ * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)//' filename

I get the following error:

sed: -and expression # 1, character 24: the numeric numeric for the `s' command can not be zero (s /// 0)

I'm assuming that the s/ only applies to strings and not numbers, is there a way to correctly remove this painful string?

Til
  • 5,150
  • 13
  • 26
  • 34
D Venzi
  • 65
  • 1
  • 7

2 Answers2

2

Try this:

sed -i -e 's| \* Running on http://0\.0\.0\.0:80/ (Press CTRL+C to quit)||' filename

And usually when you are toying with this, don't add -i yet, so just:

sed -e 's| \* Running on http://0\.0\.0\.0:80/ (Press CTRL+C to quit)||' filename

When it's working, then add the -i to change file(s) inplace.

The mechanism is substitute by regex.
And many characters have special meanings in regex so you have to escape it.
The character after s will act as the separator, s#From#to# like this.
And you might want to add g flag to replace multiple occurances. s$from$to$g or so.

And in your case there're many / so might as well change it to another, | in above examples.

Til
  • 5,150
  • 13
  • 26
  • 34
1

If you use a different separator (instead of "/"), you don't have to escape everything:

sed -e 's| * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)||g' <filename>
Luis Lavaire.
  • 599
  • 5
  • 17