Totals in a file - incorrectly displaying


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Totals in a file - incorrectly displaying
# 8  
Old 12-13-2010
Quote:
Originally Posted by mcclunyboy
sorry, the 3rd column in my sample is basically an amount field. I have removed the decimal places for other reasons. Anyway, as it is an amount field the the final 2 digits are the 2 on the right of the decimal place.

Even so, my problem is the code I am using is not correctly displaying the total, it is missing the right hand digit.
$(awk '{s+=$3}END
Hmmm..... so what you're saying is that you used to have floats values in the 3-rd field. Then you converted all 3-rd field values to integers (removed the fractions). And now you're expecting the float values for the trailer/sum row?
How's that possible?

I must be uber confused. Maybe other could understand the dilemma better....
# 9  
Old 12-14-2010
I am going to try and be a bit clearer. I use the following code to display the total of all fields in a column - $(awk '{s+=$3}END {print "T, "s}'. This prints "T, Total"

Sample file:

C, 818128, 5612.13122010,,,,
C, 818129, 1598.13122010,,,,
C, 818130, 7896.13122010,,,,
C, 818131, 2655.13122010,,,,
T, 1776

I am hoping it displays 17761...can anyone explain why it doesnt?

---------- Post updated at 08:28 AM ---------- Previous update was at 05:59 AM ----------

Got it sorted...

It was down to decimal points which I have been removing, for some reason when i removed the decimal point it removed the final digit.

Reorganisation and step by step breakdown solved this problem - many thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Large File masking incorrectly happening Ç delimeter issue

The OS version is Red Hat Enterprise Linux Server release 6.10 I have a script to mask some columns with **** in a data file which is delimeted with Ç , I am using awk for the masking , when I try to mask a small file the awk works fine and masks the required column , but when the file is... (6 Replies)
Discussion started by: LinuxUser8092
6 Replies

2. UNIX for Beginners Questions & Answers

Ls incorrectly says file not found in sftp.

Hi all When I sftp to an Oracle cloud server, to a folder where there are more than 10k files, and list a small subset of files, it works OK. When I try list more than 10k files, it says file not found. Example output below. (FYI ls/mget with 6k files works OK on this server) Has anyone... (3 Replies)
Discussion started by: pdinsdale
3 Replies

3. 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

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

summarising totals in awk

awk ' FILENAME == "all" { balance += substr($0,17,13) dt = substr($0,6,8) } END { for ( name in balance ) printf("%013s %3s of %8s\n", balance/100,name,dt) | "sort " } ' all > summation using this code i wanted to take summary totals of... (3 Replies)
Discussion started by: paresh n doshi
3 Replies

8. 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

9. Shell Programming and Scripting

Writing to a log file incorrectly

I have this script: #!/bin/ksh ######### Environment Setup ######### PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac :/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge... (5 Replies)
Discussion started by: heprox
5 Replies
Login or Register to Ask a Question