I have this situation:
here is some file.conf :
1stRecord value
2ndRecord value
3rdRecord value
I need to replace value for some record. Here is my script:
correct_1stRecord='new1stValue'
correct_2ndRecord='new2ndValue'
correct_3rdRecord='new3rdValue'
function correct_record() {
sed -i 's/^$1 $(cat file.conf | grep -e "^$1" | awk '{print $2}')/$1 $correct_$1/" file.conf
}
correct_record 3rdRecord
when I run it the $correct_$1 did not switch to $correct_3rdRecord and as a result I have this record:
3rdRecord 3rdRecord
When I expect it to be:
3rdRecord new3rdValue
I was trying to modify the second part of the sed expression to /$1 $(correct_$1) byt then it was showing that command correct_3rdRecord does not exist, however (1) it is not a command but variable, (2) I did declare it above.