I have a file
xx that has the following contents:
@base_url = "http://dmstaffing-stage.herokuapp.com/"
I want to use sed to eliminate this line (replace with nothing). I have used this sed technique with several other line successfully, e.g.
sed -i 's/require "selenium-webdriver"//' xx
But my attempt for the @base_url line isn’t working. I suspect either the ” or the // in the http:// are messing it up but I can’t seem to fix!
I have tried:
$ sed 's/@base_url = "http://dmstaffing-stage.herokuapp.com/"//' xx sed: -e expression #1, char 23: unknown option to `s' $ sed 's/@base_url = \"http://dmstaffing-stage.herokuapp.com/\"//' xx sed: -e expression #1, char 24: unknown option to `s' $ sed 's/@base_url = "http:\/\/dmstaffing-stage.herokuapp.com/"//' xx sed: -e expression #1, char 58: unknown option to `s'
but none worked.
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
As mentioned, use other separator or escape the slashes. Your last try misses escape of last slash.
And as pointed out by @StephaneChazelas, escape
dot‘s as well.
And, including @terdon if
sed is not needed;
grep -Fxv, where
-F is fixed string, not regex, would be an option.
-x makes sure it matches whole lines.
A simple (very simple) benchmark with
time -v seems to favor
sed though. (GNU variants.)
sed 's/@base_url = "http:\/\/dmstaffing-stage\.herokuapp\.com\/"//' xx
To delete it completely (not leave blank line) use:
sed '/@base_url = "http:\/\/dmstaffing-stage\.herokuapp\.com\/"/d' xx | +--- Delete
Try using another separator:
sed 's|@base_url = "http://dmstaffing-stage.herokuapp.com/"||' xx
The slashes in the regex are messing up with sed’s delimiters.
But you can use different delimiters than the slash. For example:
sed 's#@base_url = "http://dmstaffing-stage.herokuapp.com/"##' xx
You can escape the slashes, like
sed -e 's/"@base_url = "http:\/\/dmstaffing-stage.herokuapp.com\/"/d'. This jungle of
/\/\//\// is a symptom of what is called LTS (Leaning Toothpick Syndrome). The best way around this is to just use another delimiter, like
; in your case, or whatever other non-alphanumeric character tickles your fancy today (and isn’t included in whatever mangling you have in mind, obviously).
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂