Heyyy 👋🏻 ! My name is Christian, an Agile Software Developer, living in Trento (IT).
I am currently working at Wonderflow.
You can read more about me.

Replace links in files with Regular Expressions


Share on Twitter

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 *


  • -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