Re: skip/delete lines with dup keys
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Tue, 26 Jul 2005 19:21:49 -0700
Jim wrote:
>
> Hi
Hello,
> I have csv file that has data something like this (Header in caps)
>
> LOAN_NO,SCORE,BAL
> 77585,740,452125
> 77585,741,450256
> 85669,658,125869
> 85669,658,122586
>
> Looking for ideas on the best way to skip/delete a line if the LOAN_NO
> repeat even if other fields ion in the record are not the same (need to
> remove lines with dup key fields).
> The code below seems to work, but there must be a better way.
> Thanks for any help
>
> Jim
> -------------------------------------
>
> # file already sorted by $id
> my $cur_id = '';
> while (<F>) {
> chomp;
> ($id,$score,$bal) = split (/,/, $_);
> next if $cur_id == $id;
> print OUT "$id,$score,$bal\n";
> $cur_id = $id;
> }
Don't fix it if it's not broken. :-)
John
--
use Perl;
program
fulfillment
.
- Follow-Ups:
- RE: skip/delete lines with dup keys
- From: Jim
- RE: skip/delete lines with dup keys
- Prev by Date: Re: 'Use Lib' problem...
- Next by Date: Re: skip/delete lines with dup keys
- Previous by thread: 'Use Lib' problem...
- Next by thread: RE: skip/delete lines with dup keys
- Index(es):
Relevant Pages
|