I'm trying to replace a string in a file:
$RELEASE = '1234';
The whitespace between RELEASE and the = symbol could be either spaces OR tabs. The quotes around the version number could be either single or double.
I currently am assuming spaces and single quotes at the moment just to try to get it working:
sed 's/$RELEASE[[:space:]]*\=[[:space:]]*'\''[0-9]*'\'';/$RELEASE = '\''1234'\'';/g' config.ini > config.ini
So after a lot of work, this works. But only if the string is spaces (as apposed to tabs) and single quotes as apposed to doubles. Here is what I have so far for trying to tackle the tabs...:
sed 's/$RELEASE([[:space:]]|\t)*\=([[:space:]]|\t)*'\''[0-9]*'\'';/$RELEASE = '\''1234'\'';/g' config.ini > config.ini
I've just read that /t isn't supported in most sed regular expressions... Is this true? Is there a [[:tab:]] type replacement? (I did try that)
Any help would be appreciated.
sed 's/^$RELEASE.*;$/$RELEASE = "foobar";/'
sed -i
(only for gnused
) instead or separate temporary file. Also you can use\s
instead of[[:space:]]
as it also includes \t and all other whitespaces.