Search & Replace in Multiple Files by reading a input file

I have a environment property file which contains:
Input file:

value1 = url1
value2 = url2
value3 = url3 and so on.

I need to search all *.xml files under directory for value1 and replace it with url1.
Same thing I have to do for all values mentioned in input file. I need script in unix bash or ksh.

try this:

find <type of file> | xargs perl -pi -e 's/value1/values2/g'
1 Like

Hi
I want to replace value1 which url1.
Program should read input file, then do search in entire directory for value1, once it find value1 do substitution for url1.

What have you tried so far? Show us...

I dont know scripting, I tried through maven plugin, but it is not working.

#!/bin/bash
cat environment.txt | while read src rep
do
 sed -i "s, $src), $rep),g" *.xml
done

Following will search the directory for specified file and do replacement at the same time.

find <type of file> | xargs perl -pi -e 's/value1/values2/g'

for instance, to find all xmls and seach abc in each file and replace with xyz

find *.xml | xargs perl -pi -e 's/abc/xyz/g'

Try this:

awk -F" = " 'NR==FNR {VAL[$1]=$2;next} {for (i in VAL) if ($0 ~ i) gsub (i, VAL)}1' propfile *.xml

Try like this:

while read a b c; do sed -e "s/$a/$c/g" R*; done < INP
If output looks good , use -i to edit the file directly ( can not undo ) .

cat INP:
value1 = url1
value2 = url2
value3 = url3

cat R1:
value1
value2
value3

value4
value2

cat R2:
value1
value2
value5