Simple command to find a string and replace it with another.

[html]

grep -rl ‘searchstring’ web | xargs sed -i ‘s/searchstring/replacementstring/g’

[/html]

To break it all down:

[html]
grep -rl ‘searchstring’ web
[/html]

This section of the command greps/searches recursively for the string ‘searchstring’ inside the directory “web”.

This is then piped to:

[html]
xargs sed -i ‘s/searchstring/replacementstring/g’
[/html]

‘searchstring’ is then replaced with ‘replacementstring’

Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@matthewc424.sg-host.com.