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

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!rpi!usenet.coe.montana.edu!news.u.washington.edu!uw-beaver!fluke!ssc-vax!brennan
  2. From: brennan@ssc-vax.boeing.com (Mike Brennan)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: A few UNIX questions (sed+awk)
  5. Message-ID: <5441@ssc-bee.ssc-vax.boeing.com>
  6. Date: 12 Aug 92 18:11:27 GMT
  7. References: <1992Aug5.235701.17614@pbhyf.PacBell.COM> <20619@sbsvax.cs.uni-sb.de>
  8. Organization: Boeing Computer Services
  9. Lines: 36
  10.  
  11.  
  12. In article <20619@sbsvax.cs.uni-sb.de>, uwe@mpi-sb.mpg.de (Uwe Waldmann) writes:
  13.  
  14. | > In article <1992Aug5.235701.17614@pbhyf.PacBell.COM>
  15. | > skataba@pbhyf.PacBell.COM (Sam Atabaki) writes:
  16. | > >2. I want to write a little "sed" script (I don't have perl) to
  17. | > >   edit patterns of the following forms:
  18. | > >      xyz abc <abcd@xy.com> kjkjkj
  19. | > >      xyz abc <abcd@xy.com>
  20. | > >   such that the <> are removed and anything delimited by <> be
  21. | > >   moved to the beginning of the line. So after the edit the two
  22. | > >   lines above will look:
  23. | > >      abcd@xy.com xyz abc kjkjkj
  24. | > >      abcd@xy.com xyz abc
  25. | > 
  26.  
  27. | The following code is more reliable (and it's only one process):
  28. |   sed -e 's/^\(.*\)<\(.*\)> *\(.*\)$/\2 \1\3/'
  29. | By the way, the sed+awk solution in article <118390003@hpcupt3.cup.hp.com>
  30. | by aakash@hpcupt3.cup.hp.com (Aakash Sahai) is even worse:  It also fails
  31. | if the <...> part is not enclosed by whitespace or if it is followed by
  32. | more than one word.  Why do so many people believe that string substitution
  33. | problems can be solved most easily using awk?
  34.  
  35. Because it is often easy, for example, this problem with an up to date
  36. version of awk as defined in 1988 AWK book:
  37.  
  38. awk  'BEGIN{ FS = " *<|> *"} ; { print $2, $1, $3 }'
  39.  
  40. --
  41. Mike Brennan
  42. brennan@boeing.com
  43.  
  44.  
  45.