public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Filter grep output of 'ps aux'
@ 2012-03-02 17:46 Tanstaafl
  2012-03-02 17:56 ` Pandu Poluan
  2012-03-02 18:02 ` Paul Hartman
  0 siblings, 2 replies; 18+ messages in thread
From: Tanstaafl @ 2012-03-02 17:46 UTC (permalink / raw
  To: Gentoo User

Does anyone know if there is a way to filter the output of ps aux to 
show only lines that have a value in the %CPU column higher than x - ie, 
1.0, or 2.0, or something like that?

Thanks



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 17:46 [gentoo-user] Filter grep output of 'ps aux' Tanstaafl
@ 2012-03-02 17:56 ` Pandu Poluan
  2012-03-02 18:03   ` Tanstaafl
  2012-03-02 18:02 ` Paul Hartman
  1 sibling, 1 reply; 18+ messages in thread
From: Pandu Poluan @ 2012-03-02 17:56 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

On Mar 3, 2012 12:49 AM, "Tanstaafl" <tanstaafl@libertytrek.org> wrote:
>
> Does anyone know if there is a way to filter the output of ps aux to show
only lines that have a value in the %CPU column higher than x - ie, 1.0, or
2.0, or something like that?
>
> Thanks
>

For that, you need awk instead of grep.

Rgds,

[-- Attachment #2: Type: text/html, Size: 445 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 17:46 [gentoo-user] Filter grep output of 'ps aux' Tanstaafl
  2012-03-02 17:56 ` Pandu Poluan
@ 2012-03-02 18:02 ` Paul Hartman
  2012-03-02 18:12   ` Tanstaafl
  2012-03-02 18:24   ` Pandu Poluan
  1 sibling, 2 replies; 18+ messages in thread
From: Paul Hartman @ 2012-03-02 18:02 UTC (permalink / raw
  To: gentoo-user

On Fri, Mar 2, 2012 at 11:46 AM, Tanstaafl <tanstaafl@libertytrek.org> wrote:
> Does anyone know if there is a way to filter the output of ps aux to show
> only lines that have a value in the %CPU column higher than x - ie, 1.0, or
> 2.0, or something like that?

ps aux | gawk '{ if ( $3 > 1.0 ) { print } }'



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 17:56 ` Pandu Poluan
@ 2012-03-02 18:03   ` Tanstaafl
  2012-03-02 18:12     ` Jason
  0 siblings, 1 reply; 18+ messages in thread
From: Tanstaafl @ 2012-03-02 18:03 UTC (permalink / raw
  To: gentoo-user

On 2012-03-02 12:56 PM, Pandu Poluan <pandu@poluan.info> wrote:
>
> On Mar 3, 2012 12:49 AM, "Tanstaafl" <tanstaafl@libertytrek.org
> <mailto:tanstaafl@libertytrek.org>> wrote:
>  >
>  > Does anyone know if there is a way to filter the output of ps aux to
> show only lines that have a value in the %CPU column higher than x - ie,
> 1.0, or 2.0, or something like that?
>  >
>  > Thanks
>  >
>
> For that, you need awk instead of grep.

Never used awk... any chance you (or someone) could provide an example 
of how to do this?

Also - would there be a way to get a running output (kind of like 
tailing a log)?



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 18:02 ` Paul Hartman
@ 2012-03-02 18:12   ` Tanstaafl
  2012-03-02 18:30     ` Alan McKinnon
  2012-03-02 18:24   ` Pandu Poluan
  1 sibling, 1 reply; 18+ messages in thread
From: Tanstaafl @ 2012-03-02 18:12 UTC (permalink / raw
  To: gentoo-user

On 2012-03-02 1:02 PM, Paul Hartman <paul.hartman+gentoo@gmail.com> wrote:
> On Fri, Mar 2, 2012 at 11:46 AM, Tanstaafl<tanstaafl@libertytrek.org>  wrote:
>> >  Does anyone know if there is a way to filter the output of ps aux to show
>> >  only lines that have a value in the %CPU column higher than x - ie, 1.0, or
>> >  2.0, or something like that?
> ps aux | gawk '{ if ( $3>  1.0 ) { print } }'

Thanks Paul! Thats a huge help...

Now if I could just get a constantly updated output of this (like 
tailing a live log), I'd be in heaven... ;)

But if this is the best I can do, it is 1000 times better...



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 18:03   ` Tanstaafl
@ 2012-03-02 18:12     ` Jason
  2012-03-02 18:32       ` Tanstaafl
  0 siblings, 1 reply; 18+ messages in thread
From: Jason @ 2012-03-02 18:12 UTC (permalink / raw
  To: gentoo-user

On Fri, Mar 02, 2012 at 01:03:55PM -0500, Tanstaafl wrote:
> Also - would there be a way to get a running output (kind of like
> tailing a log)?

watch -n1 "ps aux | gawk '{ if ( \$3 > 1.0 ) { print } }'"



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 18:02 ` Paul Hartman
  2012-03-02 18:12   ` Tanstaafl
@ 2012-03-02 18:24   ` Pandu Poluan
  2012-03-02 19:32     ` Paul Hartman
  2012-03-02 19:40     ` [gentoo-user] " Grant Edwards
  1 sibling, 2 replies; 18+ messages in thread
From: Pandu Poluan @ 2012-03-02 18:24 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 494 bytes --]

On Mar 3, 2012 1:07 AM, "Paul Hartman" <paul.hartman+gentoo@gmail.com>
wrote:
>
> On Fri, Mar 2, 2012 at 11:46 AM, Tanstaafl <tanstaafl@libertytrek.org>
wrote:
> > Does anyone know if there is a way to filter the output of ps aux to
show
> > only lines that have a value in the %CPU column higher than x - ie,
1.0, or
> > 2.0, or something like that?
>
> ps aux | gawk '{ if ( $3 > 1.0 ) { print } }'
>

Why would you use "if"? You can easily use this :

ps aux | awk '$3 > 1.0 {print}'

Rgds,

[-- Attachment #2: Type: text/html, Size: 749 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 18:12   ` Tanstaafl
@ 2012-03-02 18:30     ` Alan McKinnon
  0 siblings, 0 replies; 18+ messages in thread
From: Alan McKinnon @ 2012-03-02 18:30 UTC (permalink / raw
  To: gentoo-user

On Fri, 02 Mar 2012 13:12:04 -0500
Tanstaafl <tanstaafl@libertytrek.org> wrote:

> On 2012-03-02 1:02 PM, Paul Hartman <paul.hartman+gentoo@gmail.com>
> wrote:
> > On Fri, Mar 2, 2012 at 11:46 AM,
> > Tanstaafl<tanstaafl@libertytrek.org>  wrote:
> >> >  Does anyone know if there is a way to filter the output of ps
> >> > aux to show only lines that have a value in the %CPU column
> >> > higher than x - ie, 1.0, or 2.0, or something like that?
> > ps aux | gawk '{ if ( $3>  1.0 ) { print } }'
> 
> Thanks Paul! Thats a huge help...
> 
> Now if I could just get a constantly updated output of this (like 
> tailing a live log), I'd be in heaven... ;)
> 
> But if this is the best I can do, it is 1000 times better...
> 

try "watch"

-- 
Alan McKinnnon
alan.mckinnon@gmail.com




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 18:12     ` Jason
@ 2012-03-02 18:32       ` Tanstaafl
  2012-03-02 19:33         ` Paul Hartman
  0 siblings, 1 reply; 18+ messages in thread
From: Tanstaafl @ 2012-03-02 18:32 UTC (permalink / raw
  To: gentoo-user

On 2012-03-02 1:12 PM, Jason <gentoo@lakedaemon.net> wrote:
> On Fri, Mar 02, 2012 at 01:03:55PM -0500, Tanstaafl wrote:
>> Also - would there be a way to get a running output (kind of like
>> tailing a log)?
>
> watch -n1 "ps aux | gawk '{ if ( \$3>  1.0 ) { print } }'"

Perfect!!!

Thanks so much guys!



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 18:24   ` Pandu Poluan
@ 2012-03-02 19:32     ` Paul Hartman
  2012-03-02 19:40     ` [gentoo-user] " Grant Edwards
  1 sibling, 0 replies; 18+ messages in thread
From: Paul Hartman @ 2012-03-02 19:32 UTC (permalink / raw
  To: gentoo-user

On Fri, Mar 2, 2012 at 12:24 PM, Pandu Poluan <pandu@poluan.info> wrote:
>
> On Mar 3, 2012 1:07 AM, "Paul Hartman" <paul.hartman+gentoo@gmail.com>
> wrote:
>>
>> On Fri, Mar 2, 2012 at 11:46 AM, Tanstaafl <tanstaafl@libertytrek.org>
>> wrote:
>> > Does anyone know if there is a way to filter the output of ps aux to
>> > show
>> > only lines that have a value in the %CPU column higher than x - ie, 1.0,
>> > or
>> > 2.0, or something like that?
>>
>> ps aux | gawk '{ if ( $3 > 1.0 ) { print } }'
>>
>
> Why would you use "if"? You can easily use this :
>
> ps aux | awk '$3 > 1.0 {print}'

because I don't know awk very well ;)



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 18:32       ` Tanstaafl
@ 2012-03-02 19:33         ` Paul Hartman
  2012-03-02 20:39           ` Tanstaafl
  0 siblings, 1 reply; 18+ messages in thread
From: Paul Hartman @ 2012-03-02 19:33 UTC (permalink / raw
  To: gentoo-user

On Fri, Mar 2, 2012 at 12:32 PM, Tanstaafl <tanstaafl@libertytrek.org> wrote:
> On 2012-03-02 1:12 PM, Jason <gentoo@lakedaemon.net> wrote:
>>
>> On Fri, Mar 02, 2012 at 01:03:55PM -0500, Tanstaafl wrote:
>>>
>>> Also - would there be a way to get a running output (kind of like
>>> tailing a log)?
>>
>>
>> watch -n1 "ps aux | gawk '{ if ( \$3>  1.0 ) { print } }'"
>
>
> Perfect!!!
>
> Thanks so much guys!

And you can use the --sort options for ps to sort by cpu or anything
you like (see the manpage)



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [gentoo-user] Re: Filter grep output of 'ps aux'
  2012-03-02 18:24   ` Pandu Poluan
  2012-03-02 19:32     ` Paul Hartman
@ 2012-03-02 19:40     ` Grant Edwards
  2012-03-03  2:16       ` Pandu Poluan
  1 sibling, 1 reply; 18+ messages in thread
From: Grant Edwards @ 2012-03-02 19:40 UTC (permalink / raw
  To: gentoo-user

On 2012-03-02, Pandu Poluan <pandu@poluan.info> wrote:
> On Mar 3, 2012 1:07 AM, "Paul Hartman" <paul.hartman+gentoo@gmail.com>
> wrote:
>>
>> On Fri, Mar 2, 2012 at 11:46 AM, Tanstaafl <tanstaafl@libertytrek.org>
> wrote:
>> > Does anyone know if there is a way to filter the output of ps aux to
> show
>> > only lines that have a value in the %CPU column higher than x - ie,
> 1.0, or
>> > 2.0, or something like that?
>>
>> ps aux | gawk '{ if ( $3 > 1.0 ) { print } }'
>>
>
> Why would you use "if"? You can easily use this :
>
> ps aux | awk '$3 > 1.0 {print}'

Why would you use "{print}"?  You can easily use this:

ps aux | awk '$3 > 1.0'

;)

-- 
Grant Edwards               grant.b.edwards        Yow! Kids, don't gross me
                                  at               off ... "Adventures with
                              gmail.com            MENTAL HYGIENE" can be
                                                   carried too FAR!




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 19:33         ` Paul Hartman
@ 2012-03-02 20:39           ` Tanstaafl
  2012-03-02 20:50             ` Paul Hartman
  0 siblings, 1 reply; 18+ messages in thread
From: Tanstaafl @ 2012-03-02 20:39 UTC (permalink / raw
  To: gentoo-user

On 2012-03-02 2:33 PM, Paul Hartman <paul.hartman+gentoo@gmail.com> 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?



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 20:39           ` Tanstaafl
@ 2012-03-02 20:50             ` Paul Hartman
  2012-03-02 21:23               ` Tanstaafl
  0 siblings, 1 reply; 18+ messages in thread
From: Paul Hartman @ 2012-03-02 20:50 UTC (permalink / raw
  To: gentoo-user

On Fri, Mar 2, 2012 at 2:39 PM, Tanstaafl <tanstaafl@libertytrek.org> wrote:
> On 2012-03-02 2:33 PM, Paul Hartman <paul.hartman+gentoo@gmail.com> 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'



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 20:50             ` Paul Hartman
@ 2012-03-02 21:23               ` Tanstaafl
  2012-03-02 21:52                 ` Paul Hartman
  0 siblings, 1 reply; 18+ messages in thread
From: Tanstaafl @ 2012-03-02 21:23 UTC (permalink / raw
  To: gentoo-user

On 2012-03-02 3:50 PM, Paul Hartman <paul.hartman+gentoo@gmail.com> wrote:
> On Fri, Mar 2, 2012 at 2:39 PM, Tanstaafl<tanstaafl@libertytrek.org>  wrote:
>> On 2012-03-02 2:33 PM, Paul Hartman<paul.hartman+gentoo@gmail.com>  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...



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 21:23               ` Tanstaafl
@ 2012-03-02 21:52                 ` Paul Hartman
  2012-03-03 13:00                   ` Tanstaafl
  0 siblings, 1 reply; 18+ messages in thread
From: Paul Hartman @ 2012-03-02 21:52 UTC (permalink / raw
  To: gentoo-user

On Fri, Mar 2, 2012 at 3:23 PM, Tanstaafl <tanstaafl@libertytrek.org> wrote:
> On 2012-03-02 3:50 PM, Paul Hartman <paul.hartman+gentoo@gmail.com> wrote:
>>
>> On Fri, Mar 2, 2012 at 2:39 PM, Tanstaafl<tanstaafl@libertytrek.org>
>>  wrote:
>>>
>>> On 2012-03-02 2:33 PM, Paul Hartman<paul.hartman+gentoo@gmail.com>
>>>  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.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Re: Filter grep output of 'ps aux'
  2012-03-02 19:40     ` [gentoo-user] " Grant Edwards
@ 2012-03-03  2:16       ` Pandu Poluan
  0 siblings, 0 replies; 18+ messages in thread
From: Pandu Poluan @ 2012-03-03  2:16 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 916 bytes --]

On Mar 3, 2012 2:44 AM, "Grant Edwards" <grant.b.edwards@gmail.com> wrote:
>
> On 2012-03-02, Pandu Poluan <pandu@poluan.info> wrote:
> > On Mar 3, 2012 1:07 AM, "Paul Hartman" <paul.hartman+gentoo@gmail.com>
> > wrote:
> >>
> >> On Fri, Mar 2, 2012 at 11:46 AM, Tanstaafl <tanstaafl@libertytrek.org>
> > wrote:
> >> > Does anyone know if there is a way to filter the output of ps aux to
> > show
> >> > only lines that have a value in the %CPU column higher than x - ie,
> > 1.0, or
> >> > 2.0, or something like that?
> >>
> >> ps aux | gawk '{ if ( $3 > 1.0 ) { print } }'
> >>
> >
> > Why would you use "if"? You can easily use this :
> >
> > ps aux | awk '$3 > 1.0 {print}'
>
> Why would you use "{print}"?  You can easily use this:
>
> ps aux | awk '$3 > 1.0'
>
> ;)
>

Ahaha, true... that's the default action if no action block is provided. I
usually just print the fields I need in the action block.

Rgds,

[-- Attachment #2: Type: text/html, Size: 1532 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [gentoo-user] Filter grep output of 'ps aux'
  2012-03-02 21:52                 ` Paul Hartman
@ 2012-03-03 13:00                   ` Tanstaafl
  0 siblings, 0 replies; 18+ messages in thread
From: Tanstaafl @ 2012-03-03 13:00 UTC (permalink / raw
  To: gentoo-user

On 2012-03-02 4:52 PM, Paul Hartman <paul.hartman+gentoo@gmail.com> wrote:
> On Fri, Mar 2, 2012 at 3:23 PM, Tanstaafl<tanstaafl@libertytrek.org>  wrote:
>> 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

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

Aaargh! I could have sworn I tried that... but yes, now it works 
perfectly...

Thanks Paul - Gentoo support is the best, even for general linux 
questions like this...



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-03-03 13:01 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-02 17:46 [gentoo-user] Filter grep output of 'ps aux' Tanstaafl
2012-03-02 17:56 ` Pandu Poluan
2012-03-02 18:03   ` Tanstaafl
2012-03-02 18:12     ` Jason
2012-03-02 18:32       ` Tanstaafl
2012-03-02 19:33         ` Paul Hartman
2012-03-02 20:39           ` Tanstaafl
2012-03-02 20:50             ` Paul Hartman
2012-03-02 21:23               ` Tanstaafl
2012-03-02 21:52                 ` Paul Hartman
2012-03-03 13:00                   ` Tanstaafl
2012-03-02 18:02 ` Paul Hartman
2012-03-02 18:12   ` Tanstaafl
2012-03-02 18:30     ` Alan McKinnon
2012-03-02 18:24   ` Pandu Poluan
2012-03-02 19:32     ` Paul Hartman
2012-03-02 19:40     ` [gentoo-user] " Grant Edwards
2012-03-03  2:16       ` Pandu Poluan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox