Re: awk leaking memory during arithmetic?

From: Dan Nelson <dnelson_at_allantgroup.com>
Date: Mon, 4 Oct 2004 12:22:24 -0500
In the last episode (Oct 04), Brian Reichert said:
> I may be misremembering some awk lore, but this still seems like
> undesired behavior.  Essentially, I'm trying to sum up some numbers,
> but awk spin, chewing up memory, until it drops a huge core file.
> 
>   # uname -a
>   FreeBSD backup.internal 5.2.1-RELEASE FreeBSD 5.2.1-RELEASE #1: Mon Sep 27
>   19:27:46 EDT 200	 root_at_backup2.internal:/usr/src/sys/i386/compile/FILESERVER  i386
>   
>   # cat test_list | awk '{print $1}'
>   53999616
>   53999616
>   53311488
>   102475776
>   257134592
>   858624
>   512909312
>   1147392
>   39385174
>   35815424
> 
>   # cat test_list | awk '{ t += $1 } END {print $t}'
>   awk in malloc(): error: allocation failed

I think "print t" is what you want here.  $t would refer to the t'th
field in the line, and it looks like awk tried to resize the array out
to 1111037014 entries and failed.

-- 
	Dan Nelson
	dnelson_at_allantgroup.com
Received on Mon Oct 04 2004 - 15:22:27 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:15 UTC