home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!usc!cs.utexas.edu!hermes.chpc.utexas.edu!news.utdallas.edu!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: Sed with shell variables
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1992Aug21.134656.20370@news.eng.convex.com>
- Date: Fri, 21 Aug 1992 13:46:56 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <2701@nlsun1.oracle.nl> <1992Aug21.110719.11512@siesoft.co.uk>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 49
-
- From the keyboard of stuart@siesoft.co.uk:
- :rgasch@nl.oracle.com (Robert Gasch) writes:
- :: Using sed to edit strings is usually a nice and practical
- :: method of doing so. I you want to change a pattern you usually
- :: say:
- :: echo $something|sed 's/pattern1/pattern2/'
- ::
- :: The problem I ran into is that I can't get shell variables to
- :: work as arguments. When I type
- :: echo $something|sed 's/$this_pattern_var/$that_pattern_var/'
- ::
- :: sed throws up on me. I've tried various combinations of quotation
- :: marks without success. Is there an easy way of doing this??
- ::
- :
- :echo "$something" | sed 's/'"$this_pattern_var"'/'"$that_pattern_var"'/'
- :
- :The double quotes around the shell variables are only
- :needed if they contain any spaces (or tabs).
-
- Untrue.
-
- % set x='*' y='?'
- % sed s/$x/$y/
- s/: No such file or directory
-
- This actually seems to work in a Bourne-shell, which tells
- me that there's a difference in when retokenization happens,
- which was news to me.
-
- Things like this drive people from either traditional shell
- into rc or perl, where you have more control over this.
-
- You also will have a problem if your pattern contains delimiters,
- which is a bit of a hassle to work around.
-
- Things like this drive people into perl, which doesn't have
- that problem either.
-
- Of course, you can do these things in a traditional shell.
- But the variable quoting is a hassle, and the escaping of
- the regexp delims is a hassle.
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
-
- We should develop anti-satellite weapons because we could not have prevailed
- without them in 'Red Storm Rising'. --Vice President Dan Quayle
-