Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!netnews.upenn.edu!jes From: jes@mbio.med.upenn.edu (Joe Smith) Newsgroups: comp.unix.questions Subject: Re: Killing with awk and grep Message-ID:Date: 15 Aug 89 13:31:37 GMT References: <303@opus.NMSU.EDU> <4128@cps3xx.UUCP> <2361@wyse.wyse.com> Sender: news@netnews.upenn.edu Distribution: usa Organization: University of Pennsylvania, Philadelphia, PA Lines: 29 In-reply-to: bob@wyse.wyse.com's message of 14 Aug 89 23:52:36 GMT > Why not let awk do all the pattern processing: > ps -aux | awk '$10 ~ /^-sleeper$/{print "kill -9 " $2}' | sh A good idea, but you will get burned doing this (I know, I have scorches to prove it!). Ps is not particularly nice about making it's output easy to parse. Some fields have spaces; and, under some circumstances, others may run together (i.e., no space in between). Also I think ps output differs among different Unix flavors (I'm only familiar with BSD). All this means that using the default awk fields is a Bad Thing. If you want to use awk, just scan the whole line: /-sleeper/ && !/awk/ { print $2 } # field 2 (pid) is (always?) ok If you want to look at fields, you'll have to use the substring function (only in new awk) to break up the lines, but beware, it won't be portable. Not that this topic is worth a lot of discussion, but I'd hate to see someone else get burned on this.