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

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!olivea!spool.mu.edu!umn.edu!noc.msc.net!news.stolaf.edu!news.stolaf.edu!guenther
  2. From: guenther@StOlaf.edu (Philip Guenther)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: seding with variables and /s question
  5. Message-ID: <GUENTHER.92Sep12181519@lars.StOlaf.edu>
  6. Date: 13 Sep 92 01:15:19 GMT
  7. References: <lb4q5tINNaef@jethro.Corp.Sun.COM>
  8. Sender: news@news.stolaf.edu
  9. Organization: St. Olaf College, Northfield, MN USA
  10. Lines: 31
  11. In-Reply-To: tmhoff@oogoody.Corp.Sun.COM's message of 12 Sep 1992 22:01:33 GMT
  12.  
  13. In article <lb4q5tINNaef@jethro.Corp.Sun.COM> tmhoff@oogoody.Corp.Sun.COM (Todd Hoff) writes:
  14.  
  15. >    I'm having a hard time using variables to specify search patterns
  16. > containind /s in sed. Say my home development directory path is in
  17. > $DEVEL and my destination path is in $DEST. Since these are path
  18. > specifications they contain /s and when I do something like: sed -e
  19. > 's/$DEVEL/$DEST/' $file > $destfile sed barfs on the /s. I've tried
  20. > lots of variations. Any clues? 
  21.  
  22. >   Thanx
  23.  
  24. A quick check of the sed(1) man page shows...
  25.  
  26.   (2)s/regular expression/replacement/flags [...]
  27.            Any character may be used instead of `/'.
  28.            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  29.  
  30. Also, neither csh nor sh do variable substitution within single
  31. quotes, so you would want to enter:
  32.  
  33. sed -e "s:$DEVEL:$DEST:" $file > $destfile
  34.  
  35. In fact, as ":" isn't a special character, you needn't do any quoting.
  36. Now if $DEVEL or $DEST contained special characters/whitespace...
  37.  
  38. Philip Guenther
  39. --
  40. guenther@stolaf.edu (Philip Guenther)       | The ACC might agree with me,
  41. Student Sys Prog, Academic Computing Center | but with that bunch, (and me)
  42. St Olaf College, Northfield, MN 55057-1001  | you never know... :-) :-| :-(
  43. "Life makes sense?  LIFE MAKES SENSE!!?  Where do people get these ideas?"-me
  44.