print out result from data file

i got a data file which contains all the pid,ppid,user,command,pcpu,start_time,status. I wanted to display out the pcpu which is greater than 0.

i uses awk'{if($5 > 0){print}}' filename.txt but is printing out result which not i wanted. Is there any way which i can print out those pcpu which is greater than 0?

Both of them should work

awk '{if($5 > 0){print}}' file
awk '$5 > 0 {print}' file

Could you please put some sample data of your file.

Dear thms sum,

can u plz provide an example of ur need?

regards,
Pankaj

i have attached a sample of my data file. i would like to only display cpu which is above 0 from the data file. how can go with awk to make it display?

awk '$(NF-2)>0' input

thanks radoulov!!! its works!!! but can u explain y got to NF-2?

Some CMD column values contain spaces so for Awk (with default FS) %CPU is not always $5,
therefore as long as START and STAT values don't contain spaces $(NF-2)
(the number of fields of the crrent record - 2) will work :slight_smile:

oic... so is counting from the back of the field that doesnt contain any space!!! Thanks a lot radoulov!!!

not the back of the 'field', but rather the back of the 'record' where 'record' is 'line'