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
calculate 13 months ago andrea_mussap Shell Programming and Scripting 4 11-21-2007 05:14 PM
calculate 13 months ago andrea_mussap Shell Programming and Scripting 3 11-16-2007 12:18 PM
Count No of Records in File without counting Header and Trailer Records guiguy Shell Programming and Scripting 2 06-07-2007 09:15 AM
How To Calculate krishna_sicsr Shell Programming and Scripting 1 03-28-2007 07:24 AM
How to calculate with awk whatisthis Shell Programming and Scripting 4 11-09-2005 09:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 06-10-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
You could use awk, but then you have a requirement to find the frequency based on the first 2 characters of the 4th field.

I am not sure, how you can extract characters using awk.

Probably someone could post a solution for that.

Vino
Reply With Quote
Forum Sponsor
  #9  
Old 06-10-2005
r2007's Avatar
Registered User
 

Join Date: Jun 2005
Location: China
Posts: 73
Code:
awk -F"\t" '{a[substr($4,1,2)]++}END{for (i in a) print i,a[i]}'
Reply With Quote
  #10  
Old 06-10-2005
Registered User
 

Join Date: Jun 2005
Posts: 47
Quote:
Originally Posted by r2007
for 2nd question:
Code:
awk -F"\t" '{a[$3]+=$2}END{for (i in a) print i,a[i]}'
[not test]
Thanks a lot. It is working properly but I cannot understand how it is working.

When you this
a[$3]+=$2
this means that you put the 3rd field in a table and you assign his value to be equal with the sum of its second field?????
And why we don't get many times the same 3rd field when printing (I don't want to be printed many times, I just want to understand how it is working).

Cheers
Reply With Quote
  #11  
Old 06-10-2005
r2007's Avatar
Registered User
 

Join Date: Jun 2005
Location: China
Posts: 73
Quote:
AWK variables are dynamic; they come into existence when they are first used. Their values are either floating-point numbers or strings, or both, depending upon how they are used.
All arrays in AWK are associative, i.e. indexed by string values.
a[$3]+=$2 <===> a[$3]=a[$3]+$2
with the following data
386 8192 A423 CC0177 40
586 65536 A424 CC0182 670
486 16384 A423 CC0183 100
486 16384 A425 CC0184 80
65000 4096 B407 EE1027 80


AWK processes data line by line
line #1: a["A423"]=a["A423"]+8192=8129
line #2: a["A424"]=a["A424"]+65536=65536
line #3: a["A423"]=a["A423"]+16384=8129+16384
...
...
...

Sorry for my pool English. That's all what I can explain to you.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:51 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