sed - replace unix var with windows var

Hi,

I'm trying to convert a unix shell script to windows and can't figure out how to find the unix variable with the '$' and surround it with '%<var>%' instead. i.e.:

Code:
PATH=/usr/openwin/bin:/usr/ccs/bin:/usr/ucb:/usr/sbin:/apps/utils/dbbin:/apps/utils/dt/bin:/usr/dt/bin:$PATH.

In many cases, the variable is within a line and not the end.
 
You mean this?

Code:
> echo \$PATH | sed 's/\$PATH/\%\<PATH\>\%/'
%<PATH>%

Escape all special characters with backslashes.
 
Thanks Dutch Daemon for your reply. I should've been more precise with my example. The script had multiple variable names, not just PATH. Changing one when I know the name wasn't an issue, finding others and surrounding them with '%' was my problem.
 
Unixgod, this is my first posting to the forum. I am not familiar with the protocols. I hadn't know this isn't the right place for a question like this. Please let me know which sub-category I should've gone to.
 
rmathew84 said:
In many cases, the variable is within a line and not the end.

Could you give a better example ? Are you looking for all $VAR to be escaped by %<VAR>% ? Something like this:

$ cat output

Code:
PATH=/bin:$PATH:/voodoo/magic
FOO=$BAR:yellow
BAR=this:$FOO

$ cat output | sed -n 's/\(\$\)\([0-9A-Za-z]*\)/%<\2>%/p'

Code:
PATH=/bin:%<PATH>%:/voodoo/magic
FOO=%<BAR>%:yellow
BAR=this:%<FOO>%
 
Back
Top