I'm an italian agile software developer, living in Trento (IT)     More about me

Replace links in files with Regular Expressions

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