Hi all, I'm having trouble coming up with a sed or awk to do the following...
I have a text file with lines that look like:
%let MYVAR = somevalue;
I need to replace somevalue (alphanumeric) with the value of a shell variable.
This I can do with
However, sometimes this statement is followed by a comment on the same line:
%let MYVAR = somevalue; *** purpose of this variable;
OR
%let MYVAR = somevalue; /* purpose of this variable */
I need to account for all these possibilities and preserve the comment if it exists. I've been trying to use kleen stars and end of line anchors to no avail. Help please!
Thanks
I have a text file with lines that look like:
%let MYVAR = somevalue;
I need to replace somevalue (alphanumeric) with the value of a shell variable.
This I can do with
Code:
sed -i "s#\(%let MYVAR \= \)\(.*\)\(\;\)#\1$SHELLVAR\3#" $FILE
However, sometimes this statement is followed by a comment on the same line:
%let MYVAR = somevalue; *** purpose of this variable;
OR
%let MYVAR = somevalue; /* purpose of this variable */
I need to account for all these possibilities and preserve the comment if it exists. I've been trying to use kleen stars and end of line anchors to no avail. Help please!
Thanks