home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!sun-barr!cs.utexas.edu!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: Sort problem . .
- Message-ID: <1992Jul29.132526.2223@convex.com>
- Originator: tchrist@convex.convex.com
- Sender: usenet@convex.com (news access account)
- Nntp-Posting-Host: convex.convex.com
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- Organization: CONVEX Realtime Development, Colorado Springs, CO
- References: <1992Jul28.095415.4640@prl.dec.com> <1992Jul28.102938.12375@news.eng.convex.com> <1992Jul29.044600.27445@cerberus.bhpese.oz.au>
- Date: Wed, 29 Jul 1992 13:25:26 GMT
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 37
-
- From the keyboard of Sm@cerberus.bhpese.oz.au (Scott Merrilees):
- :Tom Christiansen <tchrist@convex.COM> writes:
- :> ps axu | (read line; echo "$line"; sort +3rn)
- :
- :ps axu | sed 1d | sort -nr +3
-
- I was trying to avoid sending the data stream through yet another
- process in the chain. But apparently starting a subshell was too much
- trouble:
-
- $ time sh -c 'ps axu | (read line; echo "$line"; sort +3rn)' > /dev/null
- 1.508u 1.635s 0:01.89 50.0% 0+0k 46+3io 113pf+0w
-
- $ time sh -c "ps axu | sed 1d | sort -nr +3" > /dev/null
- 1.482u 1.534s 0:01.81 50.0% 0+0k 32+5io 106pf+0w
-
- On the other hand, a bit to my surprise, this
-
- #!/usr/bin/perl
- open(PS, "ps axu |") || die "cannot fork: $!";
- print scalar(<PS>);
- while (<PS>) { push(@lines, $_); push(@idx, (split(' '))[3]); }
- print @lines [ sort { $idx[$b] <=> $idx[$a]; } 0..$#idx ];
-
- runs in this time:
-
- 0.779u 0.107s 0:00.53 50.0% 0+0k 3+0io 82pf+0w
-
- Which is better than either of the pure shell solutions.
-
- --tom
-
- --
- "GUIs normally make it simple to accomplish simple actions and impossible
- to accomplish complex actions." --Doug Gwyn (22/Jun/91 in comp.unix.wizards)
-
- Tom Christiansen tchrist@convex.com convex!tchrist
-