Wednesday 23 January 2013

Global search and replace with sed

So today I needed to replace a few hundred href link in varying content today.  Here's my take on solving it. This works in zsh.  I think for bash you need to add the do and done parts of the for loop, i'm not sure.

for file in `grep -lR "href=\"\/static\/" .`; sudo sed -i -e 's/href=\"\/static\//href=\"\/applications\/static\//g' $file