I use the following sed syntax in order to replace the timezone string with #timezone
actually sed command replace it ,
but in case after timezone string we have one space or more then sed not replaced it
my question what I need to change in the sed syntax in order to replace the timezone string
on the both cases
- After timezone string we not have any space
-
After timezone string we a have space or more
sed -i '/timezone$/s/timezone/#timezone/' file
You can try:
you need to add the
?after a space, that will make the space optional. Also you’ll have to add the-roption to make sed understand extended regex.Also you are not specifying the backup extension after the
-ioption.