home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3555 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  1.3 KB

  1. Path: sparky!uunet!mcsun!uknet!siesoft!wstuart!stuart
  2. From: stuart@wstuart (Stuart Hood)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Sed with shell variables
  5. Message-ID: <1992Aug21.110719.11512@siesoft.co.uk>
  6. Date: 21 Aug 92 11:07:19 GMT
  7. References: <2701@nlsun1.oracle.nl>
  8. Sender: news@siesoft.co.uk (Usenet News)
  9. Reply-To: stuart@siesoft.co.uk
  10. Organization: Siemens Nixdorf Information Systems Ltd.
  11. Lines: 25
  12. X-Newsreader: Tin 1.1 PL4
  13.  
  14. rgasch@nl.oracle.com (Robert Gasch) writes:
  15. : Using sed to edit strings is usually a nice and practical
  16. : method of doing so. I you want to change a pattern you usually
  17. : say:
  18. :     echo $something|sed 's/pattern1/pattern2/'
  19. : The problem I ran into is that I can't get shell variables to
  20. : work as arguments. When I type
  21. :     echo $something|sed 's/$this_pattern_var/$that_pattern_var/'
  22. : sed throws up on me. I've tried various combinations of quotation
  23. : marks without success. Is there an easy way of doing this??
  24.  
  25. echo "$something" | sed 's/'"$this_pattern_var"'/'"$that_pattern_var"'/'
  26.  
  27. The double quotes around the shell variables are only
  28. needed if they contain any spaces (or tabs).
  29.  
  30. Stuart.
  31. -
  32. --
  33. S I E M E N S  Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
  34. -------------  Phone: + 44-344-850892          Email: stuart@siesoft.co.uk
  35. N I X D O R F  - Never let ignorance stand in the way of a good argument -
  36.