Replace links in files with Regular Expressions

Published on

You need to replace a string with special characters (like http://) and don’t want to do that manually?

I’ve found the solution.

__

I tried to escape each ‘/’ with ‘/’ but sed didn’t like that.

Instead of replacing each ‘/’ just replace the placeholders for the regular expression with ‘#’!

Like this :


$ sed -i.bak s#http://your-address.com/images/#https://s3-eu-west-1.amazonaws.com/cf.img/posts/#g *

Explanation:

  • -i.bak is need, to prevent sed to cry around, it will make a backup of the files that you can simply remove with rm *.bak

    • at the end means ‘search all files’



I found the solution on this [forum](http://www.linuxforums.org/forum/newbie/102173-help-w-sed-parsing-special-characters.html)

Here, have a slice of pizza 🍕