Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed/awk replacement

Status
Not open for further replies.

LunaPan

Programmer
Jan 13, 2004
25
US
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
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
 
And this ?
sed -i "s#\(%let MYVAR \= \)[^;]*#\1${SHELLVAR}#" $FILE

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
*Sigh* I was making things more complicated than they needed to be as usual... thanks PH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top