grep -rl "pattern" /path/to/search | xargs sed -i 's/search_pattern/replace_pattern/g'
grep -rl "pattern" /path/to/search
: Recursively search for files containing the specified pattern in the given directory (/path/to/search
). The -r
option indicates a recursive search, and the -l
option prints only the names of files with matching lines.
|
: Redirects the output of the previous command as input to the next command.
xargs
: Builds and executes command lines from standard input. It takes input from the pipeline and passes it as arguments to the specified command.
sed -i 's/search_pattern/replace_pattern/g'
: Uses sed to perform in-place (inline) replacement of the specified search pattern with the replace pattern in the files received from xargs. The -i
option indicates in-place editing, and the s/search_pattern/replace_pattern/g
expression is the substitution command to replace all occurrences of "search_pattern" with "replace_pattern" globally in each file.