Thursday, May 10, 2018

Replace String in Multiple Files Linux Bash

We can copy all file paths into a file. Let's call the file name as `list`.
There are multiple ways of creating `list`. Here are some.
ls > list
grep -l "FIND_STRING" file_path > list
In file_path you can mention something like *.java for example to search all java files alone.

Below is the bash script which you can put in an executable file and run.
#!/usr/bin/ksh
for var in `cat list`
do
sed -i "s/FIND_STRING/REPLACE_STRING/g" $var
done
UA-39217154-2