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
Format output using awk in script. bperl Shell Programming and Scripting 8 01-14-2008 01:09 AM
[need help] output format from awk bucci Shell Programming and Scripting 6 02-09-2007 04:41 AM
format output Tornado Shell Programming and Scripting 7 11-19-2006 06:17 AM
ls output format tonyt UNIX for Dummies Questions & Answers 6 11-23-2001 11:31 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-24-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Output in a particular format using AWK

Hi All,

I am trying to check if if column 5 is greater than 90. If greater it will print the term in column 6, else if all are within limit, then it will output "Size is within limit". I can't seem to do that with the below code. The output should only be 1 statement of "Size is within the limit" since all column 5 numbers are less 90. Can somebody advise me what's wrong with my code ?

Input:

/aaa 0 0 0 0 /zzz
/aaa 240553 145567 70931 68 /
/aaa 1170399 800131 311749 72 /qqq
zz 0 0 0 0 /rrr
/xxx 288445 139404 120197 54 /ttt
/xxx 6048174 1946727 4040966 33 /ggg
/xxx 336337 225215 77489 75 /uuu
/xxx 8813861 2025333 6700390 24 /ooo
zzz 496704 35864 460840 8 /ppp
aaa 3073262 1757331 1254466 59 /hhh
aaa 140074829 106235104 32438977 77 /lll
ddd 6048174 1946727 4040966 33 /vvvv
ddd 140074829 106235104 32438977 77 /nnn

Code:
BEGIN {}
{
if ($5 > 90) Dir = $6; printf("%5s is over 90%.Pls take note!\n",Dir); 
if ($5 < 90) printf("Size is within Limit.\n");
}
END{}
My Output from the above code:

$ nawk -f awk_proto sys_info2.txt
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
is over 90%.PPls take note!
Size is within Limit.
  #2 (permalink)  
Old 01-24-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Add the braces
Code:
if ($5 > 90) {Dir = $6; printf("%5s is over 90%.Pls take note!\n",Dir); }
  #3 (permalink)  
Old 01-24-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Hi anbu,

My output now is below:

$ nawk -f awk_proto sys_info2.txt
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.
Size is within limit.


Can i output only 1 of the above statement when all are within the limits? Once 1 of the value is not within the limits, this statement would not be displayed.
  #4 (permalink)  
Old 01-24-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk '
{
if ($5 > 90) {Dir = $6; printf("%5s is over 90%.Pls take note!\n",Dir); flag=1}
}
END{ if( flag != 1 ) { printf("Size is within Limit.\n"); }' file
  #5 (permalink)  
Old 01-24-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Hi Anbu,

It works fine with that code of yours. Thanks alot!
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 05:08 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