home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!tamsun.tamu.edu!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!friedman
- From: friedman@gnu.ai.mit.edu (Noah Friedman)
- Newsgroups: comp.unix.shell
- Subject: Re: seding with variables and /s question
- Message-ID: <FRIEDMAN.92Sep13220500@nutrimat.gnu.ai.mit.edu>
- Date: 14 Sep 92 02:05:00 GMT
- References: <lb4q5tINNaef@jethro.Corp.Sun.COM>
- Sender: news@ai.mit.edu
- Organization: Free Software Foundation, 675 Mass Ave. Cambridge, MA 02139
- Lines: 18
- In-reply-to: tmhoff@oogoody.Corp.Sun.COM's message of 12 Sep 92 22:01:33 GMT
-
- In article <lb4q5tINNaef@jethro.Corp.Sun.COM> tmhoff@oogoody.Corp.Sun.COM (Todd Hoff) writes:
- >I'm having a hard time using variables to specify search patterns containind /s
- >in sed. Say my home development directory path is in $DEVEL and my destination
- >path is in $DEST. Since these are path specifications they contain /s and when
- >I do something like: sed -e 's/$DEVEL/$DEST/' $file > $destfile
- >sed barfs on the /s. I've tried lots of variations. Any clues?
-
- Yes. You'll have to quote all the special characters in your variable
- so they won't confuse sed. Example:
-
- QDEVEL=`echo "${DEVEL}" | sed 's/\([][*.\\\/?+|^$]\)/\\\1/g'`
- QDEST=`echo "${DEST}" | sed 's/\([][*.\\\/?+|^$]\)/\\\1/g'`
-
-
- sed -e "s/${QDEVEL}/${QDEST}" ${file} > ${destfile}
-
- Note that I quote some characters like `+' that are normally harmless. But
- to GNU sed this is a special character.
-