I am executing below script for search and replace in a file. search values assigned to a array S from a file Replace value assigned to another array R from a file. from the file it's replacing only last value instead of all values. what could be the mistake. If I use hard coded multiple sed command instead of loop it's working and without having assigned files.
#!/bin/bash
jmx_file_name=$1
S=( `cat "test.txt" `)
R=( `cat "test1.txt" `)
while [ $X -ge 0 ];
do
echo ${S[X]}
echo ${R[X]}
sed -i "s/${S[X]}/\${${R[X]}}/g" $jmx_file_name
let X--;
done