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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 04:20 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 06:39 AM
Delimited files hrshah74 Shell Programming and Scripting 4 02-01-2006 12:42 PM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 09:24 AM
add increment field when first field changes azekry Shell Programming and Scripting 2 11-14-2005 04:21 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-19-2007
rauphelhunter rauphelhunter is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 23
How to perfrom summation for particular delimited field?

Hi,

Please help to share your thought about how to perfrom summation for particular delimited field, and output to the particular file based on

HTML Code:
-rw-r--r--   1 abc   other          3094 Oct 19 09:40 0132019832-ps5_online_cdrm.unl
-rw-r--r--   1 abc   other          1588 Oct 19 09:47 0132019832-ps5_online_cdrn.unl
-rw-r--r--   1 abc   other          2523 Oct 19 09:54 0132019832-ps5_online_cdro.unl
-rw-r--r--   1 abc   other           947 Oct 19 10:01 0132019832-ps5_online_cdrp.unl
-rw-r--r--   1 abc   other          1300 Oct 19 10:09 0132019832-ps5_online_cdrq.unl
-rw-r--r--   1 abc   other           410 Oct 19 10:16 0132019832-ps5_online_cdrr.unl
-rw-r--r--   1 abc   other          4253 Oct 19 10:23 0132019832-ps5_online_cdrs.unl
-rw-r--r--   1 abc   other         10195 Oct 19 10:31 0132019832-ps5_online_cdrt.unl
-rw-r--r--   1 abc   other          1053 Oct 19 10:38 0132019832-ps5_online_cdru.unl
Each file will have content like this in which separated with delimiter "|".
HTML Code:
1603823|010|4|CDR|0132019832|||3002|0194212739|||||||N|Y|Y|2007-08-30 23:42:42|||17||-0.1|16.5951|||MO019|-0.1|16.5951|0|||
1603863|010|4|CDR|0132019832|||3002|01997564444|||||||N|Y|Y|2007-08-30 23:42:53|||14||-0.1|16.4251|||MO019|-0.1|16.4251|0|||
1603912|010|4|CDR|0132019832|||3005|0135305303|||||||N|Y|Y|2007-08-30 23:43:07|||9||-0.1|16.1851||3GMid|MO013|-0.1|16.1851|0|||
1603930|010|4|CDR|0132019832|||3002|0192504561|||||||N|Y|Y|2007-08-30 23:43:13|||17||-0.1|16.0851|||MO019|-0.1|16.0851|0|||
1603948|010|4|CDR|0132019832|||3004|0126440226|||||||N|Y|Y|2007-08-30 23:43:18|||15||-0.2|15.8851|||MO012|-0.2|15.8851|0|||
1603975|010|4|CDR|0132019832|||3007|0175152680|||||||N|Y|Y|2007-08-30 23:43:28|||13||-0.2|15.6151|||MO017|-0.2|15.6151|0|||
1603996|010|4|CDR|0132019832|||3004|0125329005|||||||N|Y|Y|2007-08-30 23:43:34|||18||-0.2|15.4151|||MO012|-0.2|15.4151|0|||
1604034|010|4|CDR|0132019832|||3005|0137508649|||||||N|Y|Y|2007-08-30 23:43:44|||11||-0.1|15.2451|||MO013|-0.1|15.2451|0|||
The ultimate result of all values in field 24 will be summed up and output to file say a.txt ,while field 5 and total sum value must be separated by "|"

Say when cat output(a.txt)
0132019832| -1.1


Need help...!
  #2 (permalink)  
Old 10-19-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557

Code:
awk 'BEGIN{FS="|"}
{
 a[$5]=a[$5]+$24
}
END {
     for (i in a) print a[i]"|"i > "outfile"
}
' "file"

just for one file.
  #3 (permalink)  
Old 10-19-2007
rauphelhunter rauphelhunter is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 23
Hi ghostdog74, It works fine !..

Anyone else know how to perform multiple files ?

Regards,
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 12:24 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