On Fri, Mar 2, 2012 at 3:23 PM, Tanstaafl <[email protected]> wrote:
> On 2012-03-02 3:50 PM, Paul Hartman <[email protected]> wrote:
>>
>> On Fri, Mar 2, 2012 at 2:39 PM, Tanstaafl<[email protected]>
>>  wrote:
>>>
>>> On 2012-03-02 2:33 PM, Paul Hartman<[email protected]>
>>>  wrote:
>>>>
>>>>
>>>> And you can use the --sort options for ps to sort by cpu or anything
>>>> you like (see the manpage)
>>>
>>>
>>>
>>> Even better, thanks Paul...
>>>
>>> watch -n1 "ps aux --sort=-%cpu | gawk '{ if ( \$3>  1.0 ) { print } }'"
>>>
>>> does exactly what I want...
>>>
>>> Hmmm... is there an easy way to include the column headers?
>>
>>
>> To build on Grant's suggestion:
>> ps aux --sort %cpu | gawk 'NR==1; $3>  0'
>
>
> Hmmm.. ok, this works beautifully, thanks!
>
> But when I tried to incorporate it into the watch command like the other
> one:
>
> Original:
>
> watch -n1 "ps aux --sort=-%cpu | gawk '{ if ( \$3 > 1.0 ) { print } }'"
>
> Attempt at incorporating your command into this:
> watch -n1 "ps aux --sort=-%cpu | gawk 'NR==1; $3 > 0'"
>
> it gives me a syntax error:
>
> Every 1.0s: ps aux --sort=-%cpu | gawk 'NR==1; >  0'
>                                                            Fri Mar  2
> 16:19:01 2012
>
> gawk: NR==1; >  0
> gawk:        ^ syntax error
>
> Any ideas on how to get this working in the watch version
>
> Thanks Paul, this will be very useful to me...
>

Put a backslash before the $, it needs to be escaped in that context.

Reply via email to