![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to print data between 2 lines in a file | kamesh83 | UNIX for Advanced & Expert Users | 4 | 2 Weeks Ago 05:11 PM |
| Print out a row of data | Streetrcr | UNIX for Dummies Questions & Answers | 4 | 03-17-2008 03:57 AM |
| print a function result in new file | kamel.seg | Shell Programming and Scripting | 0 | 12-31-2007 08:57 AM |
| Outputting formatted Result log file from old 30000 lines result log<help required> | vikas.iet | Shell Programming and Scripting | 5 | 12-02-2007 07:43 PM |
| Logging HP-UX print data | pmaths | UNIX for Dummies Questions & Answers | 0 | 04-23-2007 05:45 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Both of them should work
Code:
awk '{if($5 > 0){print}}' file
awk '$5 > 0 {print}' file
|
|
#3
|
|||
|
|||
|
Dear thms sum,
can u plz provide an example of ur need? regards, Pankaj |
|
#4
|
|||
|
|||
|
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?
|
|
#5
|
||||
|
||||
|
Code:
awk '$(NF-2)>0' input |
|
#6
|
|||
|
|||
|
thanks radoulov!!! its works!!! but can u explain y got to NF-2?
|
|
#7
|
||||
|
||||
|
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 |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|