sed 's/foobar/$string/g'.... can't do this?

Geoff Clare gwc at root.co.uk
Fri Feb 1 02:26:54 AEST 1991


In <8872 at star.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:

}In article <2586 at root44.co.uk>,
}	gwc at root.co.uk (Geoff Clare) writes:
})
})Xstring=`sed 's/[\/&\\]/\\&/g' <<!
})$string
})!
})`
})sed 's/foobar/'"$Xstring"'/g'

}Did you actually try your solution?  I guess not.

Yes and no.  I tested the sed command on its own, but then stuck it
inside backquotes without noticing that extra quoting would be required.
Sorry about that - I'll try to be more careful in future.

}The following works:

}Xstring=`sed 's/[\/&\\\\]/\\\\&/g' <<!
}$string
}!
}`

Yes it does.  I would have doubled the backslash in "\/" as well, but
clearly it's not needed.

-- 
Geoff Clare <gwc at root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273



More information about the Comp.unix.shell mailing list