[comp.unix.questions] Killing with awk vs. cut

ritter@cs.msstate.edu (Thomas H. Ritter) (08/15/89)

In a recent article:

> From: Tricia Gardenhire <tgardenh@nmsu.edu>
> Subject: Summarize: killing with awk and grep
> 
> more about how grep, and awk work now.  Any way, to summarize, the
> easiest way to do this was:
> 
> kill `ps -aux | fgrep -e -sleeper | egrep -v fgrep | awk '{print $2}'`
> 
> Most other ideas were similar, but were more involved shell scripts.

I agree that this is an easy and convient solution, but one thing struck
me as I read people's postings to your question. 

All the solutions I saw used awk to get the second column of the
ps listing. Why use such a general purpose tool for so simple
a task? SystemV provides the cut command. eg.

kill `ps -aux | fgrep -e -sleeper | egrep -v fgrep | cut -d" " -f5`

This solution uses a program that is considerably cheaper in
overhead than awk. (awk is an interpreted language)

I know that some 4.XBSD systems don't provide cut. 
But, I think if a nice tool is available use it. (portablilty aside)

Tom Ritter
ritter@cs.msstate.edu

abcscnge@csuna.csun.edu (Scott "The Pseudo-Hacker" Neugroschl) (08/23/89)

In article <20608@adm.BRL.MIL> ritter@cs.msstate.edu (Thomas H. Ritter) writes:
]In a recent article:
]All the solutions I saw used awk to get the second column of the
]ps listing. Why use such a general purpose tool for so simple
]a task? SystemV provides the cut command. eg.
]
]kill `ps -aux | fgrep -e -sleeper | egrep -v fgrep | cut -d" " -f5`

The problem with cut is that if you specify the delimiter with -d, then
consecutive delimiters will return empty strings: e.g.

a<blank><blank>b

where <blank> is a single blank:

cut -d" " -f2 returns an empty string, and cut -d" " -f3 returns the b

Scott
-- 
Scott "The Pseudo-Hacker" Neugroschl
UUCP:  ...!sm.unisys.com!csun!csuna.csun.edu!abcscnge
-- Beat me, Whip me, make me code in Ada
-- Disclaimers?  We don't need no stinking disclaimers!!!