1834643 Members
3578 Online
110069 Solutions
New Discussion

sed "s/\//\\\//g"

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

sed "s/\//\\\//g"

The variable F is:
#com.hp.java.file.start=/etc/hp/dir1/dir2/dir3/myconfig.xml
VAL1=`echo $F | cut -d"=" -f1`
#com.hp.java.file.start
OLD=`echo $F | sed "s/\//\\\//g"`
#hoping to get com.hp.java.file.start=\/etc\/hp\/dir1\/dir2\/dir3\/myconfig.xml
VAL2=`echo $F | cut -d"=" -f2`
#/etc/hp/dir1/dir2/dir3/myconfig.xml
VALZ=`echo $VAL2 | sed "s/\/etc\/hp\///g"`
#dir1/dir2/dir3/myconfig.xml
VALZ2="$VAL2"
#/etc/hp/dir1/dir2/dir3/myconfig.xml
VALZ3=`echo $VALZ2 | sed "s/\//\\\//g"`
#\/etc\/hp\/dir1\/dir2\/dir3\/myconfig.xml<\/A>

NEW="${OLD}=${VALZ3}"

#Up to there it seems to do what I expect, but the following sed gets confused with all the /'s and \'s!
#How can I quote the sed properly still allowing variable substitution?
#I've tried all the ' " ` 's!
sed "s/`$OLD`/`$NEW`/g" ${PROPFILE} > ${PROPFILE}.tmp
mv ${PROPFILE}.tmp $PROPFILE

Later,
Bill

(PS, regarding my question yeste...
It works for me (tm)
4 REPLIES 4
Thierry Poels_1
Honored Contributor
Solution

Re: sed "s/\//\\\//g"

hi Bill,

change the delimiter, too many /'s ;)

sed "s;$OLD;$NEW;g" ${PROPFILE} > ${PROPFILE}.tmp

good luck,
Thierry.

BTW I would also change the to to get rid of excesive backslashes.

All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Mark van Hassel
Respected Contributor

Re: sed "s/\//\\\//g"

Hi,

It should be like this:

sed s'/'$OLD'/'$NEW'/g' ${PROPFILE} >$PORPFILE}.tmp
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
Praveen Bezawada
Respected Contributor

Re: sed "s/\//\\\//g"

Hi
On posix
sed s/${OLD}/${NEW}/g
seems to be working fine for me..
Bill McNAMARA_1
Honored Contributor

Re: sed "s/\//\\\//g"

Yeah, guys, thanks for you help, especially Thierry, you helped make the script more readable. In fact I was really screwing up.. I was looking at the wrong output file!! I'm going to post this script up here soon in any case, see what you all think of it.. after all you helped write my element of it..
It's a type of collectinfo based on the nickel script by Robert Sakic of the German Response Center only that I've modified it to add some more stuff. I'll email him my copy and see if he want's to keep my bits in any case.

See www.grc.hp.com/docs/nickel/
for the original script.

Later,
Bill
It works for me (tm)