Search and Replace Strings with Grep in UNIX
Posted by Dexter Nelson: Tuesday, May 6, 2014 (2:39 PM)
How To Search And Replace Strings With Grep (UNIX Commands)
As a programmer and marketer, when I create tools (like a member center), often times I just copy whole directories to save time. It's smart, since I don't want to re-write code from scratch every time.
I also don't want to have to spend hours editing every single file, especially if it has tons of them.
So I use grep to search and replace strings in every file in a directory.
Here is the UNIX Command format.
# grep -rl / | xargs sed -i 's///g';
I'm writing it this way for a few reasons, namely it's the easiest format to follow, and I've seen some crazy ways of doing this. I prefer the pipe because it saves on having to backslash comment special characters (I think).
Below is an image from a new site that I set up.
I have several subdomains (one for each tool) and you can see how it looks in real life.