user6677057
user6677057

Reputation: 35

associative arrays limit in awk. memory usage

I have a file with more than 20 million records and want to sum 5th column for every unique value of 1st column, i have used the code below.

cat test.txt |awk 'BEGIN{FS="|"}{a[$1]+=$5;}END{for(i in a) print i"|"a[i];}'

maximum value of a[i] in the output is limited to 9999.

kindly help me...any solution??

Upvotes: 0

Views: 376

Answers (1)

James Brown
James Brown

Reputation: 37424

$ cat > file
1||||a|NOTICE A LETTER IN FIFTH
1||||5
2||||57
2||||34535
3||||34535353
3||||1
1||||1
$ cat file|awk 'BEGIN{FS="|"}{a[$1]+=$5;}END{for(i in a) print i"|"a[i];}'
1: 6
2: 34592
3: 34535354

What do you get with my data above?

Upvotes: 1

Related Questions