summarising totals in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting summarising totals in awk
# 1  
Old 10-27-2008
summarising totals in awk

Code:
awk '
FILENAME == "all"    { balance[substr($0,14,3)] += substr($0,17,13)
                       dt = substr($0,6,8)  }
END                       { for ( name in balance )
    printf("%013s %3s of %8s\n", balance[name]/100,name,dt) | "sort "
} ' all > summation


using this code i wanted to take summary totals of
different categories.

for large amounts i could not get desired results

Code:
sample result is like this:
0000001065456 5CR of 18042008
0000014860090 2CR of 18042008
0001.3641e+07 2DR of 18042008
001.49954e+08 3CR of 18042008
002.29408e+08 4CR of 18042008
002.42195e+08 4DR of 18042008
006.79463e+07 3DR of 18042008

any help please....

Last edited by radoulov; 10-27-2008 at 07:49 AM.. Reason: added code tags
# 2  
Old 10-27-2008
hi paresh,

Can u provide sample data...
# 3  
Old 10-27-2008
Code:
0000 180420082cr00004125616000000000000000018042008 0015
0000 180420082cr00000350855000000000000000018042008 0016
0000 180420082cr00000024629000000000000000018042008 0017
0000 180420082cr00000030846000000000000000018042008 0018
0000 180420082cr00000005098000000000000000018042008 0019
0000 180420082cr00000238180000000000000000018042008 0020
0000 180420082cr00000120089000000000000000018042008 0021
0000 180420082cr00000007061000000000000000018042008 0022
0000 180420082cr00001006775000000000000000018042008 0023
0000 180420082cr00000148528000000000000000018042008 0024
0000 180420082cr00000186099000000000000000018042008 0025
0000 180420082cr00000036106000000000000000018042008 0026
0000 180420082cr00000055062000000000000000018042008 0027
0000 180420082cr00000071755000000000000000018042008 0028
0000 180420082cr00000389249000000000000000018042008 0029
0000 180420082cr00000004845000000000000000018042008 0030
0000 180420082cr00002000000000000000000000018042008 0031
0000 180420082cr00000004568000000000000000018042008 0032
0000 180420082cr00000024784000000000000000018042008 0033
0000 180420082cr00000725673000000000000000018042008 0034
0000 180420082cr00000260800000000000000000018042008 0035
0000 180420082cr00000116708000000000000000018042008 0036
0000 180420082cr00000211000000000000000000018042008 0037


Last edited by radoulov; 10-27-2008 at 07:48 AM.. Reason: added code tags
# 4  
Old 10-27-2008
Try this one

Code:
awk '
FILENAME == "all" { balance[substr($0,14,3)] += substr($0,17,13)
dt = substr($0,6,8) }
END { for ( name in balance )
printf("%13.0lf %3s of %8s\n", balance[name]/100,name,dt) | "sort "
} ' all > summation


Last edited by ranjithpr; 10-27-2008 at 07:48 AM.. Reason: added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create bins with totals and percentage

I would like to create bins to get histogram with totals and percentage, e.g. starting from 0. If possible to set the minimum and maximum value in the bins ( in my case value min=0 and max=20 ) Input file 8 5 10 1 11 4 12 4 12 4 13 5 16 7 18 9 16 9 17 7 18 5 19 5 20 1 21 7 (10 Replies)
Discussion started by: jiam912
10 Replies

2. Shell Programming and Scripting

Grand totals in awk

I have a one-liner script like this that gives a total of everything in various directories: for i in *; do (cd $i && cd statelist && echo $i && ls -la |awk 'NR>3 {SUM += $5}\ END { print "Total number of elements " SUM }');done It works just great but at the end I want to print a grand... (3 Replies)
Discussion started by: newbie2010
3 Replies

3. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

4. Shell Programming and Scripting

Totals in a file - incorrectly displaying

Afternoon, I have a script which creates/modifies data into a formatted csv. The trailer record should display 2 columns, the first is a static entry of "T" to identify it as a trailer record. The 2nd is a total of amounts in a column throughout the entire file. My total isn't displaying... (8 Replies)
Discussion started by: mcclunyboy
8 Replies

5. Shell Programming and Scripting

Trying to combine upload and download totals from txt file by ip address

I have two files, uploads.txt and downloads.txt. I would like to combine the columns of these files based on the ip address. How can I best do this? Uploads.txt 192.168.0.147 1565369 192.168.0.13 1664855 192.168.0.6 1332868 Downloads.txt 192.168.0.147 9838820 192.168.0.18 12051718... (7 Replies)
Discussion started by: zanyspydude
7 Replies

6. Shell Programming and Scripting

Report Totals

Hello, I have written a script in a previous server and its being migrated to a new server. I'm trying to debug my script since i've had to make minor changes to it to get it to work. I'm having a hard time getting my totals to populate here is the syntax DUMP_COUNT=`sqlplus -S... (4 Replies)
Discussion started by: senormarquez
4 Replies

7. Shell Programming and Scripting

loop through files splitting up and totals

I need to go through files in a folder and names that match write to a new file and have counts of the seperate names. fairly new to scripting and know what I want but do not know how to script it. example of what I need follows PACKAGE='ls -A1 | tr -s '-' '^' | cut -f2 -d"^" | sort -n' loop... (2 Replies)
Discussion started by: freddie999
2 Replies

8. Shell Programming and Scripting

[Solved] Find Specific records from file and add totals into variables

Hi Eveyone, I am working on one shell script to find the specific records from data file and add the totals into variables and print them. you can find the sample data file below for more clarification. Sample Data File: PXSTYL00__20090803USA CHCART00__20090803IND... (7 Replies)
Discussion started by: veeru
7 Replies

9. Shell Programming and Scripting

Calculating totals in AWK

Hello, With the following small script I list the size of documents belonging to a certain user by each time selecting the bytes-field of that file ($7). Now it fills the array with every file it finds so in the end the output of some users contains up to 200.000 numbers. So how can I calculate... (7 Replies)
Discussion started by: Hille
7 Replies
Login or Register to Ask a Question