Pattern match and replace indirect directory reference using sed

Hi,

I need a ksh script to replace indirect directory references in an .ini file with a env variable using sed or awk.

The .ini file is for example as such:

A=..
B=../
C=../..
D=../../
E=../bin
F=../../bin
G=../../bin/xml
H=../../bin/xml/

Need to replace an instance of .. or ../.. with %HOME%

so

A=%HOME%
B=%HOME%/
C=%HOME%
D=%HOME%/
E=%HOME%/bin
F=%HOME%/bin
G=%HOME%/bin/xml
H=%HOME%/bin/xml/

Well, try

sed -r 's#\.\.(/\.\.)*#%HOME%#' file

-Ranga

1 Like

Unix sed needs

sed 's#\.\.\(/\.\.\)\{0,1\}#%HOME%#' file
1 Like