The following solution isn't as short as the other solutions, but it will
allow you to maintain the order of the original file:
#!/usr/bin/perl
use warnings;
use strict;
my($last, $last_rec);
while () {
my @data = split;
if ($last and $data[0] != $last) {
print $last_rec;
} elsif (eof)
On Wednesday, August 25, 2004 11:56 PM, balaji venkat wrote:
> The following code will do the required task.
>
> #! /usr/bin/perl
>
> open (FILE,"test789.pl");
> @array1 = ;
> $last = pop(@array1);
> print $last;
No, I don't think you read the requirement correctly.
Either solution from myself
loan tran wrote:
I would like to know if there is any way to process a
file using perl to get rid of extra records based on a
key value.
My key is the 1st field and in my output file I only
want 1 record per key and it has to be the last record
in the file.
So for example here is my file:
1 5 4
aji venkat [mailto:[EMAIL PROTECTED]
Sent: Wed 8/25/2004 8:56 PM
To: Jeremy Kister; [EMAIL PROTECTED]
Cc:
Subject: Re: get last record in a file
The following code will do the required task.
#! /usr/bin/perl
The following code will do the required task.
#! /usr/bin/perl
open (FILE,"test789.pl");
@array1 = ;
$last = pop(@array1);
print $last;
--- Jeremy Kister
<[EMAIL PROTECTED]> wrote:
> On Wednesday, August 25, 2004 6:15 PM, I wrote:
> > not extensively tested:
>
> this is a bit more tested:
On Wednesday, August 25, 2004 6:15 PM, I wrote:
> not extensively tested:
this is a bit more tested:
#!/usr/local/bin/perl
open(F, "file.txt");
while(){
chomp(my $line = $_);
my ($key) = $line =~ /^(\S+)\s/;
$hash{$key} = $line;
}
close F;
foreach my $value (values %hash){
print "$val
On Wednesday, August 25, 2004 5:57 PM, loan tran wrote:
> So for example here is my file:
> 1 5 4
> 1 0 2
> 1 2 2
> 2 0 2
> 3 0 3
> 3 4 6
> And here is the output file I want:
> 1 2 2
> 2 0 2
> 3 4 6
not extensively tested:
#!/usr/local/bin/perl
open(F, "file.txt");
while(){
Loan Tran wrote:
I would like to know if there is any way to process a
file using perl to get rid of extra records based on a
key value.
My key is the 1st field and in my output file I only
want 1 record per key and it has to be the last record
in the file.
So for example here is my file:
1 5 4
1
I would like to know if there is any way to process a
file using perl to get rid of extra records based on a
key value.
My key is the 1st field and in my output file I only
want 1 record per key and it has to be the last record
in the file.
So for example here is my file:
1 5 4
1 0 2
1 2 2