I’m having some issues in doing a simple regex using sed.
I’ve to do some replacement in a sql file and I’m trying to use sed.
I should replace the url of some links. The links are in the following format:
www.site1.com/blog/2012/12/12
I would like to replace site1 with site2 in all links.
To find these links I’ve written the following regex:
(site1.com)\/blog\/\d{4}\/\d{2}\/\d{2}
And seems to wokr properly.
Using sed to do the replacement things I’ve written the following code
cat back.sql | sed 's:(site1.com)\/blog\/\d{4}\/\d{2}\/\d{2}:site2.com:' > fixed.sql
But it seems is not working..
seddoes not support\d(not to my knowing at least), and supports{4}only with extended regular expressions.as a basic regular expression (requires lots of escaping):
ps. you don’t need to escape slashes if you use different delemiters (
:)