I am working on a bash script, trying to find a regexp in a file, substitute (with sed) a part of regexp corresponding to a float number by this number divided by 2.
Example:
echo set NEX \"2.00\" > testfile
cat testfile
Output:
set NEX "2.00"
Command:
sed -i -r 's/(set NEX ")([0-9.]+)(")/echo \1$(echo "scale=2;\2\/2" | bc)\3/e' testfile
cat testfile
Output:
set NEX 1.00
So, my problem is that echo in sed command seems not to escape and interpret the double quote returned by \1 and \3. I tried many escaping tricks like using \ or '"'"' but it still does not work. I will be happy to have some help and to learn more about bash, my studies in shell are far behind me :)
Thank you in advance!
zet