Hey ๐Ÿ‘‹๐Ÿป

My name is Christian, an Agile Developer, living in Trento (IT)

I write good code at Wonderflow

You can follow me on and Github


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