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