# sed - replace unix var with windows var



## rmathew84 (Mar 24, 2011)

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.: 


```
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.


----------



## UNIXgod (Mar 24, 2011)

OP please read the sticky here:
http://forums.freebsd.org/showthread.php?t=3888


----------



## DutchDaemon (Mar 25, 2011)

You mean this?


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

Escape all special characters with backslashes.


----------



## rmathew84 (Mar 25, 2011)

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.


----------



## rmathew84 (Mar 25, 2011)

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.


----------



## DutchDaemon (Mar 25, 2011)

The one it was moved to ..


----------



## _martin (Mar 26, 2011)

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`


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

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


```
PATH=/bin:%<PATH>%:/voodoo/magic
FOO=%<BAR>%:yellow
BAR=this:%<FOO>%
```


----------



## rmathew84 (Mar 28, 2011)

Thanks MatoAtlantis. That was exactly what I was looking for.


----------

