[comp.unix.questions] Unnecessarily long pipelines

gwc@root.co.uk (Geoff Clare) (07/18/90)

In <price.648165820@chakra> price@chakra.unl.edu (Chad Price) writes:

>z=`ps -aug | grep $2 | grep -v grep | grep -v csh | grep -v kill | awk '{ print $2 }'`

I usually just chuckle to myself when I see things like this, but I decided
this time it's worth a comment.

Why is it that people string together lots of "grep" commands in a
pipeline, when they could do the same job with a single "sed" or "awk"
command?  In this case it's even worse, because "awk" is already in
there as well!
-- 
Geoff Clare <gwc@root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, Hayne Street, London EC1A 9HH, England.   Tel: +44-71-315-6600

richard@aiai.ed.ac.uk (Richard Tobin) (07/20/90)

In article <2358@root44.co.uk> gwc@root.co.uk (Geoff Clare) writes:
>Why is it that people string together lots of "grep" commands in a
>pipeline, when they could do the same job with a single "sed" or "awk"
>command?

Because they can remember how to do it without thinking of course.  Just
like most csh users type "mv fred.c fred.c.old" instead of the shorter
"mv fred.c{,.old}"

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin@uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin

leo@ehviea.ine.philips.nl (Leo de Wit) (07/22/90)

In article <3043@skye.ed.ac.uk> richard@aiai.UUCP (Richard Tobin) writes:
|In article <2358@root44.co.uk> gwc@root.co.uk (Geoff Clare) writes:
|>Why is it that people string together lots of "grep" commands in a
|>pipeline, when they could do the same job with a single "sed" or "awk"
|>command?
|
|Because they can remember how to do it without thinking of course.  Just
|like most csh users type "mv fred.c fred.c.old" instead of the shorter
|"mv fred.c{,.old}"

Yup, especially if your csh supports filename completion (this also
allows you to check whether there's already a *.old file without
retyping the command).

    Leo.

davidsen@antarctica.crd.GE.COM (william E Davidsen) (07/23/90)

In article <2358@root44.co.uk>, gwc@root.co.uk (Geoff Clare) writes:

|> Why is it that people string together lots of "grep" commands in a
|> pipeline, when they could do the same job with a single "sed" or "awk"
|> command?  In this case it's even worse, because "awk" is already in
|> there as well!

  Or egrep, or whatever. Maybe becauses it's easier to type?

tif@doorstop.austin.ibm.com (Paul Chamberlain) (07/23/90)

This should be in comp.unix.gripes

In article <3043@skye.ed.ac.uk> richard@aiai.UUCP (Richard Tobin) writes:
|In article <2358@root44.co.uk> gwc@root.co.uk (Geoff Clare) writes:
|>Why is it that people string together lots of "grep" commands ...
|Because they can remember how to do it without thinking of course.  Just
|like most csh users type "mv fred.c fred.c.old" instead of the shorter
|"mv fred.c{,.old}"

I interpret this answer as saying "its easier to type than think" which
is often true.  But, when writing a shell script I would hope that any
reasonably good shell programmer would spend the extra 2 minutes thinking
time to get a script that will run twice as fast.  Especially if the
script in question is one that will run often or during heavy system load.
(I seem to recall this one was trying to kill runaway process forking.)

I have seen a question answered with a shell script which invoked awk once
for each line in a potentially large file.  I spent a few minutes on it and
had a solution that would easily run ten times as fast.  The awk solution
was more obvious than looking up or experimenting with some less familiar
features of the shell.  (details omitted and fading from memory)

Paul Chamberlain | I do NOT represent IBM         tif@doorstop, sc30661@ausvm6
512/838-7008     | ...!cs.utexas.edu!ibmaus!auschs!doorstop.austin.ibm.com!tif