Sharcoux Sharcoux - 1 year ago 98
Bash Question

Use sed with variable that contains dot

I am trying to replace (for instance) 6.0 by 6.1 in a file, without 640 being replaced by 6.1

I have currently:

sed -i "s/$previousName/$newName/" 'myFile'

I think that the solution could be in here, but I don't find the right solution.

EDIT both string are inside a variable and the question this is supposed to be a duplicate of doesn't treat this case

Answer Source

Using an inner sed:

sed -i "s@$(echo $previousName | sed 's/\./\\./g')@$newName@g" myFile