Denham Eva said:
> Hello,
>
> I am very much a novice at perl and probably bitten off more than I can
> chew
> here.
> I have a file, which is a dump of a database - so it is a fixed file
> format.
> The problem is that I am struggling to manipulate it correctly. I have
> been
> trying for two days now to get a program to work. The idea is to remove
> the
> duplicate records, ie a record begins with Name and ends with Values End.
> The program that I have thus far, is  pathetic in the sense I have opened
> three files, the file below, a data file for cleaned data, and a file for
> capturing the usernames already processed. But I have got stuck on how to
> compare and work through the file line for line and then only to capture
> the
> lines that are not duplicated.
> Please help - I am running out of time.

You forgot to attach your code.  If you let us see what you've done it
is usually easier to provide relevant help.

I'm not sure I completely understand your problem, but here is a script
which will remove records with duplicate names.


#!/bin/perl -w

use strict;

$/ = "#". "-" x 77 . "\n";

my %seen;

while (<>)
{
    if (my ($name) = /^Name          : +(\S+)/)
    {
        next if $seen{$name};
        $seen{$name}++;
    }
    print;
}

__END__


The trick is to set $/ to the line which is separating your records so
that each record is read in as a whole.  Then I simply extract the name
from the record and don't print it if it has been seen already.  I
suspect that your actual requirements will differ here.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to