Dear All,
I have the file abc.txt
cat abc.txt
This is a test file
Nothing is new in this world
I want to replace
"This is a test file" to "Text is replaced"
Code
Code:
FindString='This is a test file'
ReplaceString='Text is replaced'
Findarray=(`echo $FindString | tr ' ' ' '`)
ReplaceArray=(`echo $ReplaceString | tr ' ' ' '`)
# Length
num_new_items=${#Findarray[@]};
# Length of replace array
ReplaceArrayLength=${#ReplaceArray[@]};
echo "Replace Array Length : $ReplaceArrayLength"
echo "Length $num_new_items";
for (( i=0;i<$ReplaceArrayLength;i++)); do
sed -i s/${Findarray[$i]}/${ReplaceArray[$i]}/g TestFile
# echo ${array[$i]};
# echo $i;
done
But this is not effective.
Any idea how to replace entire line either using sed or awk or any other utility.
Thanks in Advance,
Pramod