Bellow solution can be applied to replace contents of a file (or of more files).
First, you can itterate through the mapfile like this:
while IFS=: read -r desc new old;do #IFS is used to set the delimiter, : in your case
echo "description=$desc - old value:$old - to be replaced with : $new"
#i usually apply this echo as a cross check that all field are read correctly
#more actions here like:
#sed -i "s/$old/$new/g" file1
done <mapfile
If you uncomment above sed line you will call sed inside the loop, using the variables that you read from mapfile like this :
sed "s/prj1/DCMS_DEMO/g"
for the first line of mapfile
sed "s/blk1/de_top/g"
for the second line of mapfile, etc
This solution has a pitfall: sed will be called many times, one time per line read from mapfile and thus performance will be slow.
To speed things up you can "built" a "replacement script" that can feed sed one time at the end. To do so we can do something like this inside the loop:
echo "s/$old/$new/g;" >>replacements
When the loop is finish and the whole sed replacement script is ready, you can call sed one time at the end like this:
sed -f replacements file1
Demo with sed replacement script
#!/bin/bash
clear
echo "Original File1"
cat file1
while IFS=: read -r desc new old;do
echo "s/$old/$new/g;" >>replacements
done <mapfile
echo && echo "Replacements for sed"
cat replacements
echo && echo "file1 replaced"
sed -f replacements file1
rm replacements
#Output:
Original File1
blk3 : 0% : 0%
blk1 : 0.68% : 0.99%
blk2 : 0.00% : 0.00%
OVERALL_STATUS=0.23%
PARTIAL_STATUS=0.33%
Replacements for sed
s/prj1/DCMS_DEMO/g;
s/blk1/de_top/g;
s/blk2/new_block2/g;
s/blk3/test/g;
s/checklist1/Block_DV/g;
file1 replaced
test : 0% : 0%
de_top : 0.68% : 0.99%
new_block2 : 0.00% : 0.00%
OVERALL_STATUS=0.23%
PARTIAL_STATUS=0.33%
Tips:
If you need to make changes permanent on file1 use sed -i
If you need to apply the same sed script in more files insid a directory you can do it like :
sed -i -f replacements * #or /dir/* or *.txt etc
mapfile
has three fields, defined by:
and you want the 3d field to replace the 1st field in the target file. Is that correct? iii) explain how we can find the target file. You said there are many files in different subdirectories.blk3 : 0% : 0%
is a filename? You need to rename filenames or you need to replace contents inside files? Is still unclear to me