The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 13
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?
Reply With Quote
Forum Sponsor
  #2  
Old 01-30-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 146
Both of them should work

Code:
awk '{if($5 > 0){print}}' file
awk '$5 > 0 {print}' file
Could you please put some sample data of your file.
Reply With Quote
  #3  
Old 01-30-2008
Registered User
 

Join Date: Apr 2007
Location: Kolkata
Posts: 81
Dear thms sum,

can u plz provide an example of ur need?


regards,
Pankaj
Reply With Quote
  #4  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 13
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?
Attached Files
File Type: txt tes.txt (6.4 KB, 13 views)
Reply With Quote
  #5  
Old 01-30-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,855
Code:
awk '$(NF-2)>0' input
Reply With Quote
  #6  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 13
thanks radoulov!!! its works!!! but can u explain y got to NF-2?
Reply With Quote
  #7  
Old 01-30-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,855
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0