Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!pyrltd!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.shell Subject: Re: sed 's/foobar/$string/g'.... can't do this? Keywords: sed Message-ID: <2586@root44.co.uk> Date: 28 Jan 91 13:27:37 GMT References: <1991Jan17.003856.469@unicorn.cc.wwu.edu> <135@edi386.UUCP> <1991Jan21.124531.27867@siesoft.co.uk> <7ejp01gY0c.900@amdahl.uts.a <1064@mwtech.UUCP> Distribution: comp Organization: UniSoft Ltd., London, England Lines: 22 In <1064@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: > sed 's/foobar/'"$string"'/g' >BTW: There's no simple way to stop sed from complaining when the variable >`string' contains a slash, except if you know that it does contain a slash >and use some other seperator in the s-commando. Yes there is. Simply create a copy of $string with '/' changed to '\/'. While you're at it, you can treat '&' and '\' the same way to prevent sed from interpreting '&', '\1', etc. if they happen to occur in $string. Xstring=`sed 's/[\/&\\]/\\&/g' < (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273