I have some files containing lines, some of them are similar that shown below:
HETATM 2340  C2  2FN     1      15.566  27.839  11.677  1.00 24.33           C
I need to replace
2FN     1 
to
2FN D   1
so that the final result is:
HETATM 2340  C2  2FN     1      15.566  27.839  11.677  1.00 24.33           C
This is rather easy by using sed command and in the case of you always have the same words to replace
sed 's/2FN     1/2FN D   1/g' input.file > output.file
However, in the case one wants to use variables
A="2FN"
B="1"
in sed command, the result is not what is expected, I suppose due to the multiple spaces in the text to replace.
I tried several ways, such as:
A="2FN"
B="1"
S='     '
G=$(echo "$LIG${S}$LIGN")
sed 's/$G/2FN D   1/g' input.file > output.file
But no expected result has been obtained. Interestingly, by echo G variable is:
"2FN     1" 
but sed doesn't replace to
"2FN D   1"
Do you have any suggestions?
Thanks
 
    