Reputation: 3495
I'd like to use sed to remove all characters between "foo=1&" and "bar=2&" for all occurrences in an xml file.
<url>http://example.com?addr=123&foo=1&s=alkjasldkffjskdk$bar=2&f=jkdng</url>
<url>http://example.com?addr=124&foo=1&k=d93ndkdisnskiisndjdjdj$bar=2&p=dnsks</url>
Here is my sed command:
sed -e '/foo=1&/,/bar=2&/d' sample.xml
When I run this, the file is unchanged.
The above is based on this example: Find "string1" and delete between that and "string2"
Upvotes: 1
Views: 31071
Reputation: 11047
You should use
sed -i -e 's/\(foo=1&\).*\(bar=2&\)/\1\2/' your_html.xml
Upvotes: 2
Reputation: 50024
Use the substitution command instead of the delete command:
sed -e 's/\(foo=1&\).*\(bar=2&\)/\1\2/'
Upvotes: 7