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

Awk arrays and specific character matching
am relativity new to awk but what I'm trying to do is take a list of
serial numbers and parse out the duplicates, but the problem is I only
want to remove duplicate entrys if they are at certain characters of
the serial number.
(or i could just use uniq)

It's a 17 digit serial number but i only want to remove duplicates if
they appear in digit 1,2,3,4,5,6,7,8, 10,11,12 disregarding any
duplication in digit 9 or 13-17

is this posible with a awk array?

or do i need to use somthing else to acomplish this?



thanks

Report this thread to moderator Post Follow-up to this message
Old Post
GREG_D
12-03-04 08:56 AM


Re: Awk arrays and specific character matching
# Compare 17-digit serial numbers based on digits 1--8 and
# 10--12.  Discard duplicates.
{ fixed = fix($0)
if ( !(fixed in a) )
{ print
a[fixed]++
}
}

function fix(s)
{ return substr(s,1,8) substr(s,10,3)
}


Does this do what you want?

Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-03-04 08:56 PM


Re: Awk arrays and specific character matching

GREG_D wrote:
> am relativity new to awk but what I'm trying to do is take a list of
> serial numbers and parse out the duplicates, but the problem is I only
> want to remove duplicate entrys if they are at certain characters of
> the serial number.
> (or i could just use uniq)
>
> It's a 17 digit serial number but i only want to remove duplicates if
> they appear in digit 1,2,3,4,5,6,7,8, 10,11,12 disregarding any
> duplication in digit 9 or 13-17
>
> is this posible with a awk array?
>
> or do i need to use somthing else to acomplish this?

Something like this should do it if you want to keep the last occurrence
of the serial number:

awk 'BEGIN{FS=""}
{a[$1$2$3$4$5$6$7$8$10$11$12]=$0}
END{for (i in a) print a[i]}'

If you want to keep the first occurrence then it's:

awk 'BEGIN{FS=""}
{i=$1$2$3$4$5$6$7$8$10$11$12}
!(i in a){a[i]=$0}
END{for (i in a) print a[i]}'

Regards,

Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
12-03-04 08:56 PM


Re: Awk arrays and specific character matching
gregdodds@canada.com (GREG_D) wrote in message news:<f530cee6.0412022331.341444a3@posting.g
oogle.com>...
> am relativity new to awk but what I'm trying to do is take a list of
> serial numbers and parse out the duplicates, but the problem is I only
> want to remove duplicate entrys if they are at certain characters of
> the serial number.
> (or i could just use uniq)
>
> It's a 17 digit serial number but i only want to remove duplicates if
> they appear in digit 1,2,3,4,5,6,7,8, 10,11,12 disregarding any
> duplication in digit 9 or 13-17
>
> is this posible with a awk array?
>
> or do i need to use somthing else to acomplish this?
>
>
>
> thanks

hey thanks to both of you for all your help

that worked great, just what i needed

Report this thread to moderator Post Follow-up to this message
Old Post
GREG_D
12-04-04 01:55 AM


Re: Awk arrays and specific character matching
# Compare 17-digit serial numbers based on digits 1--8 and
# 10--12.  Discard duplicates.
{ fixed = fix($0)
if ( !(fixed in a) )
{ print
a[fixed]++
}
}

function fix(s)
{ return substr(s,1,8) substr(s,10,3)
}


Does this do what you want?

Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-07-04 08:59 AM


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 07:14 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.