Killing with awk and grep

Bob McGowen Wyse Technology Training bob at wyse.wyse.com
Tue Aug 15 09:52:36 AEST 1989


In article <4128 at cps3xx.UUCP> usenet at cps3xx.UUCP (Usenet file owner) writes:
>in article <303 at opus.NMSU.EDU>, tgardenh at nmsu.edu (Tricia Gardenhire) says:
>> 
>> Hi, I've been reading the man pages for awk, but they just aren't that
---deleted description---
>ps -axe | grep pattern | grep -v grep | awk '{print "kill -9 " $1}' | sh
>
>
>Robert Raisch - TechnoJunkie & UnixNut| UseNet: {uunet,mailrus}!frith!raisch

Why not let awk do all the pattern processing:

ps -aux | awk '$10 ~ /^-sleeper$/{print "kill -9 " $2}' | sh

Using the -aux as in the original question puts the user name in the first
field, the PID in the second.  The tenth field is the first part of the
command, or command name.  The tilde tells awk that the 10th field must
match the pattern as given beginning to end (of the FIELD).  The awk line
is therefor excluded because on it the tenth field is: awk

Bob McGowan  (standard disclaimer, these are my own ...)
Customer Education, Wyse Technology, San Jose, CA
..!uunet!wyse!bob
bob at wyse.com



More information about the Comp.unix.questions mailing list