Re: skip/delete lines with dup keys



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
.



Relevant Pages

  • skip/delete lines with dup keys
    ... I have csv file that has data something like this (Header in caps) ... remove lines with dup key fields). ...
    (perl.beginners)
  • Re: How do I export list of emails to excel
    ... Mrs. Linnane Haley ... The CSV file should be located in the same folder where you installed ... Jim Pickering, MVP-Outlook Express ... > I guess what I was expecting and didn't have was a typical install ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Backup or copy Address book
    ... excel sheet, what if one does not have Excel but say Open Office or just ... would it save it to the equivalent type of format found in ... Any program that can open a CSV file should open it correctly and they can ... Thank you Jim ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Import .csv error
    ... Did you set the header line on the csv file correctly? ... "Jim" wrote in message ... > 2000, Exchange 5.5). ... > rejected and listed in the error log. ...
    (microsoft.public.exchange.setup)