Help me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me
# 1  
Old 01-18-2012
Help me

Actually i have one file(shown below)

File 1:

Code:
LUN 301  17 
LUN 303  17 
LUN 304  17 
LUN 305  17 
LUN 306  34
LUN 301  34 LUN 303  34
LUN 304  68 
LUN 305  68 
LUN 306  68



Now i want output has below

Code:
Number of 17 GB luns :4
Number of 34 GB luns :3
Number of 68 GB luns :3



Please help me to give the logic for the respective task


Last edited by radoulov; 01-18-2012 at 03:42 PM.. Reason: Code tags!
# 2  
Old 01-18-2012
Is that doubled-up line a typo?

Code:
awk '{ GB[$3]++ } END { for(X in GB) print "Number of", X, "luns:", GB[X]; }' file


Last edited by Corona688; 01-18-2012 at 03:44 PM..
# 3  
Old 01-18-2012
Quote:
Originally Posted by Corona688
Is that doubled-up line a typo?

Code:
awk '{ GB[$3]++ } END { foreach(X in GB) print "Number of", X, "luns:", GB[X]; }' file

Shouldn't it be:
Code:
awk '{ GB[$3]++ } END { for(X in GB) print "Number of", X, "luns:", GB[X]; }' file

This User Gave Thanks to Franklin52 For This Post:
# 4  
Old 01-18-2012
Sorry about that. I seem to have php on the brain.
# 5  
Old 01-19-2012
showing some error while running the ksh script(error shown below)..Can u please help me

awk: cmd. line:1: { MB[$3]++ } END { foreach(X in MB) print "Number of", X, "luns:", MB[X]; }
awk: cmd. line:1: ^ syntax error
# 6  
Old 01-19-2012
Quote:
Originally Posted by Mahendranath
showing some error while running the ksh script(error shown below)..Can u please help me

awk: cmd. line:1: { MB[$3]++ } END { foreach(X in MB) print "Number of", X, "luns:", MB[X]; }
awk: cmd. line:1: ^ syntax error
Replace foreach with for as stated above.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question