![use grep to find word in multiple files use grep to find word in multiple files](https://www.cyberciti.biz/media/new/images/faq/2013/05/grep-color-hide-spam-output.png)
#USE GREP TO FIND WORD IN MULTIPLE FILES HOW TO#
replace), the g instructs the command to replace all occurrences.įine tuning 1: how to exclude directories while searching s/search/replace/g - this is the substitution command.In the current snippet I'm using it to replace text with the following parameters: Sed is a glorious Unix utility that transforms text. So in this example the output of grep is passed to the next command sed as its argument. This is a little command-line utility that takes what receives in input and passes it as argument to another program. l - print results as a simple list of file names.R - perform a recursive search, also across symbolic links.Here I'm invoking it with the following parameters: Grep is a utility for searching for strings through multiple text files. Let me now dissect it and take a quick look at the different tools in use. Assuming that you want to search for the string search through multiple files and replace it with replace, this is the one-liner: grep -RiIl 'search' | xargs sed -i 's/search/replace/g' After a bit of research I've come up with a nice solution. Often times I need to search and replace a string of text across multiple files in my Linux box.