03-26-2011
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
10 More Discussions You Might Find Interesting
1. UNIX Desktop Questions & Answers
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
2. HP-UX
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
3. Shell Programming and Scripting
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
4. Linux
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
5. Shell Programming and Scripting
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
6. Shell Programming and Scripting
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
7. UNIX for Advanced & Expert Users
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
8. Solaris
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
9. Shell Programming and Scripting
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
10. 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
IGAWK(1) Utility Commands IGAWK(1)
NAME
igawk - gawk with include files
SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ...
igawk [ all gawk options ] [ -- ] program-text file ...
DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1).
AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like
@include getopt.awk
in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path.
OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports.
EXAMPLES
cat << EOF > test.awk
@include getopt.awk
BEGIN {
while (getopt(ARGC, ARGV, "am:q") != -1)
...
}
EOF
igawk -f test.awk
SEE ALSO
gawk(1)
Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995.
AUTHOR
Arnold Robbins (arnold@skeeve.com).
Free Software Foundation Nov 3 1999 IGAWK(1)