New answers tagged replace
2
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 ...
4
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. -v inverts.
A simple (very simple) ...
3
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
3
Try using another separator:
sed 's|@base_url = "http://dmstaffing-stage.herokuapp.com/"||' xx
2
Portably:
sed -e 's/.*/ & /' -e :1 -e 's/ test3 / /g;t1' -e 's/^ //;s/ $//'
That is:
first add a space at the beginning and end of the line, to not have to consider test3 at the beginning and end specially,
replace test3 enclosed in spaces with a single space,
repeat the process as long as there are substitutions (to cover the test3 test3 cases).
...
2
I'd look for test3 wrapped with a space on either side, \s, given your example rather than try and use the word boundary notation.
For example
$ echo "test3.legacy test4.legacy test3 test3.kami" | sed 's/\stest3\s/ /g'
test3.legacy test4.legacy test3.kami
The above looks for space test3 space and replaces this with just a space.
NOTE: This won't handle ...
2
Is this what you want?
$ sed 's/\(^\| \)test3\( \|$\)/\1/g' file
test3.legacy test4.legacy test3.kami
This say
substitute
(^ start of line OR space)
test3
(space OR end of line)
with match 1 (AKA space or start of line)
Update:
And as so elegantly put by the good @Stephane Chazelas this would not take care of certain cases. Also emphasize ...
1
find . -type f -exec sed -r -i "/textword/d" {} +
Remember that the search text is interpreted as a regexp by sed (with the -r option), so it might need escaping.
Use sed -i.backup to backup original files as <filename>.backup.
1
With GNU find and sed you could:
find . -type f -print0 | xargs -0 sed -i '/^FIND$/d'
Top 50 recent answers are included

