Visit Our UNIX and Linux User Community


size for sum variable limitation on awk


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users size for sum variable limitation on awk
# 1  
Old 03-26-2011
CPU & Memory size for sum variable limitation on awk

Hello

first, truth been told, I'm not even close to be advanced user. I'm posting here because maybe my question is complicated enough to need your expert help

I need to use awk (or nawk - I don't have gawk) to validate some files by computing the total sum for a large numeric variable.
It can be that my OS does not support it or it can be as simply as modify my command

in this forum I found a simpler command, but that can indicates a limitation

/da9$ echo "12345678910 12345678910" | awk '{sum=$1; sum+=$2; print sum}'
2.46914e+10
/da9$ echo "1234567891 1234567891" | awk '{sum=$1; sum+=$2; print sum}'
2.46914e+09
/da9$ echo "123456789 123456789" | awk '{sum=$1; sum+=$2; print sum}'
246913578

/da9$ file `which awk`
/usr/bin/awk: executable (RISC System/6000) or object module
$ uname -s -r -v
AIX 1 6
$ uname -a
AIX blabla 1 6 00C608324C00

can someone help me make this sum or point me any configuration requirements?

in reality, this is the command I want to use (it can be that the inner print is causing the e+ notation, but I've tried printf and got even worse results):

cat a01.txt | nawk -F"\t" '{print $7,$8,$2";"$18}'| sort | nawk -F";" 'BEGIN{var="inicio";soma=0};{if(var!=$1) {if(var!="inicio") {print var,soma ; var=$1 ; soma=$2} else {var=$1;soma=$2}} else {var=$1;soma=soma+$2} };END{printf "\n",var,"%17.2f",soma}'

(output)

CashB Aprovado S-01 1533.44
Compr Aprovado S-01 3.23697e+09


---------- Post updated at 03:11 PM ---------- Previous update was at 02:45 PM ----------

SOLVED!!

credits to my wonderful friend Luiz Germano (who even called me at a Saturday!)

the problem really was the inner print and the solution was to format both variables

cat a01.txt | nawk -F"\t" '{print $7,$8,$2";"$18}'| sort | nawk -F";" 'BEGIN{var="inicio";soma=0};{if(var!=$1) {if(var!="inicio") {printf ("%s %17.2f\n",var,soma) ; var=$1 ; soma=$2} else {var=$1;soma=$2}} else {var=$1;soma=soma+$2} };END{printf "%s %17.2f\n",var,soma}'

you can use this as a sumif on excel - sum one column by the values of another column - sumif with awk
# 2  
Old 03-26-2011
To see the printf formatting check this : Formatted Printing (sed & awk, Second Edition)

Previous Thread | Next Thread
Test Your Knowledge in Computers #98
Difficulty: Easy
Unix was the first operating system that was written in a high-level programming language (C Language).
True or False?

10 More Discussions You Might Find Interesting

1. Linux

File size limitation in Linux

Hi friends, I tried to take a backup of my PC using tar command. But it ended with an error tar: /home/backup/back.tar.gz: Cannot write: No space left on device tar: Error is not recoverable: exiting now But i checked the disk space and there is enough space is available. ]# df Filesystem... (11 Replies)
Discussion started by: siva3492
11 Replies

2. Shell Programming and Scripting

Search two patterns using awk to print the variable sum

Coins.txt: gold 1 1986 USA American Eagle gold 1 1908 Austria-Hungary Franz Josef 100 Korona silver 10 1981 USA ingot gold 1 1984 Switzerland ingot gold 1 1979 RSA Krugerrand gold 0.5 1981 RSA Krugerrand gold 0.1 1986 PRC Panda silver 1 1986 USA Liberty dollar gold 0.25 1986 USA Liberty... (2 Replies)
Discussion started by: Ramesh M
2 Replies

3. Solaris

How to extend 2 GB file size limitation

Hello All, I am using a SunOS machine. My application creates output files for the downstream systems. However output files are restricted to 2GB of file size in SunOS due to which I am forced to create multiple files which is not supported by the downstream due to some limitations. Is... (5 Replies)
Discussion started by: pasupuleti81
5 Replies

4. UNIX for Advanced & Expert Users

Find command -size option limitation ?

Hi All, I ran code in test environment to find the files more than 1TB given below is a snippet from code: FILE_SYSTEM=/home/arun MAX_FILE_LIMIT=1099511627776 find $FILE_SYSTEM -type f -size +"$MAX_FILE_LIMIT"c -ls -xdev 2>/dev/null | while read fname do echo "File larger than... (3 Replies)
Discussion started by: Arunprasad
3 Replies

5. Shell Programming and Scripting

fetchmail - log file size limitation

Hi, I am using fetchmail in my application so as to download mails to the localhost where the application is hosted from the mailserver.Fetchmail is configured as as to run as a daemon polling mails during an interval of 1sec. So my concern here is, during each 2sec it is writing two... (10 Replies)
Discussion started by: DILEEP410
10 Replies

6. Shell Programming and Scripting

Size limitation in Tar command

Hi to every body there, I am new this forum and this is my first post. I am a new user of Unix, is there any size limitation of files while creating tar file. Thanks in advance (4 Replies)
Discussion started by: Manvar Khan
4 Replies

7. Linux

File size limitation for rcp

Hi I am trying to rcp a file from Solaris box to Linux. When the file size is 2,205,255,047, the rcp fails with the message Jan 10 01:11:53 hqsas167 rsh: pam_authenticate: error Authentication failed However when I rcp a file with smaller size - 9,434,477 - the rcp completes with... (2 Replies)
Discussion started by: schoubal
2 Replies

8. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies

9. HP-UX

HP-UX 11i - File Size Limitation And Number Of Folders Limitation

Hi All, Can anyone please clarify me the following questions: 1. Is there any file size limitation in HP-UX 11i, that I can able to create upto certain size of file (say 2 GB) and not more then that???? 2. At max. how many files we can able to keep inside a folder???? 3. How many... (2 Replies)
Discussion started by: sundeep_mohanty
2 Replies

10. UNIX Desktop Questions & Answers

Size Limitation for a user directory

Hi all, I want to set a size limitation for some user in the system, for an example, each user only have 5MB free space in the system. The user cannot user more than 5 MB space. Is it possible to do this? Thanks! (1 Reply)
Discussion started by: felix_koo
1 Replies

Featured Tech Videos