home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / shell / 3935 < prev    next >
Encoding:
Internet Message Format  |  1992-09-13  |  1.4 KB

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