|
Posted by szr on March 7, 2008, 8:26 pm
Please log in for more thread options cyrusgreats@gmail.com wrote:
>> You still don't get it. Your original code did match these lines.
>> You say it did not work. That does not add up. We're not clairvoyant
>> here, so we cannot determine what the problem really is. Post a
>> small _but_complete_ program that shows your problem.
>>
>> F.i.
>>
>> #!/usr/bin/perl
>>
>> use strict;
>> use warnings;
>>
>> while (my $line = <DATA>) {
>> next if $line =~ /^\s0.0/; # skip 0.0
>> print $line, "\n";
>>
>> }
>>
>> __DATA__
>> 0.0 19968 admin /bin/bash -l
>> 1.0 20037 admin /bin/bash -l
>> 0.2 20085 admin /bin/bash -l
>> 0.0 20363 admin /bin/bash -l
>>
>> This outputs:
>>
>> 1.0 20037 admin /bin/bash -l
>>
>> 0.2 20085 admin /bin/bash -l
>>
>> Which is exactly what I would expect. (Hint, you're missing a chomp
>> somewhere).
>>
>> HTH,
>> M4
>
>
> Well, let's start over again:
>
>
> from Linux if I send following command I get the following output:
> [root@MyWorld]#ps -eo pcpu,pid,user,args
> %CPU PID USER COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> My script below supposed to match lines that are not 0.0 such as as
> 0.2 & 1.0.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> my $cmd = "ps -eo pcpu,pid,user,args";
> my @output = `$cmd`;
>
> foreach my $line (@output) {
> next if $line =~ /^\s0.0/; # skip 0.0
> print $line, "\n";
> }
>
>
> The out put I'm getting from the above code is:
> %CPU PID USER COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> I used the while loop as Martijn Lievaart suggested above but I don't
> get any output at all!
> Thanks in advance guys and be patient with me it's Friday..
What you're trying to do can more easily be accomplished with this one
liner:
ps -eo pcpu,pid,user,args | egrep -v '^ 0.0'
Enjoy :-)
--
szr
|