Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Using an array to update duplicate records
Hello, I'm very new to awk, and am unsure if I have approched this
correctly.  I have a logfile that may have duplicate records. I need to
take the latest version.  I decided to load the records into an array
using the key as the index.  This way when a duplicate key is found it
just sets the new record in its place.

{
key = $1
accounts[key] = $0
}
END {
for (x in accounts)	{
print accounts[x]
}
}

Are there any limitations or problems with this?  THanks in advance,

Michael


Report this thread to moderator Post Follow-up to this message
Old Post
like.a.mango@gmail.com
05-31-05 08:57 AM


Re: Using an array to update duplicate records
On 30 May 2005 22:09:22 -0700, like.a.mango@gmail.com wrote:

Looks OK to me.

>END {
>	for (x in accounts)	{
>			print accounts[x]
>				}

Hint: the "in" operator doesn't print the array elements in the
sequence of input! If you want to keep this order you can use a second
array with the keys and a sequential count. Use this to access the
accounts array. If your key is sortable (i.e. something like a
timestamp YYYYMMDDhhmmss) you can pipe the result of awk to "sort".

>}
>

HTH
Axel



Report this thread to moderator Post Follow-up to this message
Old Post
Axel Sander
05-31-05 01:55 PM


Re: Using an array to update duplicate records
Thanks Axel


Report this thread to moderator Post Follow-up to this message
Old Post
like.a.mango@gmail.com
05-31-05 01:55 PM


Re: Using an array to update duplicate records

Axel Sander wrote:

> On 30 May 2005 22:09:22 -0700, like.a.mango@gmail.com wrote:
>
> Looks OK to me.
>
> 

For a large file it'll use a lot of memory. In older awks there's a
limit of (IIRC) 4096 entries in an array.

>
>
> Hint: the "in" operator doesn't print the array elements in the
> sequence of input! If you want to keep this order you can use a second
> array with the keys and a sequential count. Use this to access the
> accounts array. If your key is sortable (i.e. something like a
> timestamp YYYYMMDDhhmmss) you can pipe the result of awk to "sort".
>

If he had access to "sort" he wouldn't need to do this in awk. If you're
using "gawk", you can sort the result with "asort()" or "asorti()" but
just keeping an index seems like the best approach.

Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
05-31-05 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:38 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.