Tuesday, January 21, 2014

The magic of grep and sed and xargs

You want to get all files that have a certain string

grep -rl "ToMatch" <folder>

You then want to replace that string with another string

grep -rl "ToMatch" | xargs sed -i s/ToMatch/Replaced/g

The xargs command passes the values from "grep -rl "ToMatch" <folder>" to the sed command as arguments

For more info on how to use xargs look at http://unixhelp.ed.ac.uk/CGI/man-cgi?xargs

No comments:

Post a Comment