The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 5 12-18-2008 12:14 PM
Print out a row of data Streetrcr UNIX for Dummies Questions & Answers 4 03-17-2008 06:57 AM
print a function result in new file kamel.seg Shell Programming and Scripting 0 12-31-2007 11: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 10:43 PM
Logging HP-UX print data pmaths UNIX for Dummies Questions & Answers 0 04-23-2007 08:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-30-2008
thms_sum thms_sum is offline
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?
  #2 (permalink)  
Old 01-30-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
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.
  #3 (permalink)  
Old 01-30-2008
panknil panknil is offline
Registered User
  
 

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

can u plz provide an example of ur need?


regards,
Pankaj
  #4 (permalink)  
Old 01-30-2008
thms_sum thms_sum is offline
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, 25 views)
  #5 (permalink)  
Old 01-30-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

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

Join Date: Jan 2008
Posts: 13
thanks radoulov!!! its works!!! but can u explain y got to NF-2?
  #7 (permalink)  
Old 01-30-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0