I am trying to edit a line in a large text file using the sed command in linux.

The original line from my file.txt is:

Cg64_2043 XI1.MM1.GATE vss '0.0'

I essentially want to change the 0.0 in the line to 10. The issue is there is a ' in the line itself which seems to send the sed command. Is there a way around this? Thanks!

sed -i '/Cg64_2043 XI1.MM1.GATE vss '0.0'/s/0.0/10/' file.txt

1 Answer 1


Just use double quotes instead.

sed -i "/Cg64_2043 XI1\.MM1\.GATE vss '0\.0'/s/0\.0/10/" file.txt

And there's no point in first checking for the match and then replacing, just replace. It won't do anything it doesn't match:

sed -i "s/\(Cg64_2043 XI1\.MM1\.GATE vss \)'0\.0'/\1'10'/" file.txt

Or, if your sed supports -E (most do):

sed -E -i "s/(Cg64_2043 XI1\.MM1\.GATE vss )'0\.0'/\1'10'/" file.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.