Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!spool2.mu.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.shell Subject: Re: sed 's/foobar/$string/g'.... can't do this? Message-ID: <8872@star.cs.vu.nl> Date: 29 Jan 91 15:23:49 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> <2586@root44.co.uk> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Distribution: comp Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 32 In article <2586@root44.co.uk>, gwc@root.co.uk (Geoff Clare) writes: )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' <