f



Select unique records using key

I need to select unique records from a file based on a key in the
file.  For example, the key field is in columns 1-6.

123456ABCD
123457ABCD
123456EFGH

Output file

123456ABCD
123457ABCD

I searched the websites to find some code I could reapply but had no
luck.  Can someone please share some code that would create this
output?
Thanks.
Sandy
0
assum
8/10/2004 1:45:23 PM
comp.unix.programmer 10825 articles. 0 followers. kokososo56 (349) is leader. Post Follow

2 Replies
784 Views

Similar Articles

[PageSpeed] 54

Sandy <assum.sr@pg.com> wrote:
> I need to select unique records from a file based on a key in the
> file.  For example, the key field is in columns 1-6.

> 123456ABCD
> 123457ABCD
> 123456EFGH

> Output file

> 123456ABCD
> 123457ABCD

> I searched the websites to find some code I could reapply but had no
> luck.  Can someone please share some code that would create this
> output?

Sorry, no code, but a simple combination of the 'sort' and 'uniq'
utilities should do the job perfectly well:

sort data_file | uniq -w 6
                                  Regards, Jens
-- 
  \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de
0
Jens
8/10/2004 2:12:53 PM
Sandy wrote:
> I need to select unique records from a file based on a key in the
> file.  For example, the key field is in columns 1-6.
> 
> 123456ABCD
> 123457ABCD
> 123456EFGH
> 
> Output file
> 
> 123456ABCD
> 123457ABCD
> 
> I searched the websites to find some code I could reapply but had no
> luck.  Can someone please share some code that would create this

perl -ne'print unless $seen{ substr $_, 0, 6 }++' yourfile



John
-- 
use Perl;
program
fulfillment
0
John
8/10/2004 6:29:33 PM
Reply: