in reply to Re^2: for each unique value in a column find the max value..need perl script
in thread for each unique value in a column find the max value..need perl script

A solution: mind you, I wouldn't use this on a very big file. Not exactly the method davido was describing, but it will do.

my %id_hash; my @lines = (); open (DATA, "test.txt"); while ($line = <DATA>) { chomp $line; my @line = split /\t/ , $line; push @lines, \@line; # push the original line in an array as an an +onymous array if ($line[1] > $id_hash{$line[0]}) {$id_hash{$line[0]} = $line[1]; +} # calculate the biggest mtime for a given order id } open (OUT, ">output.txt"); foreach my $item (@lines) { my @line = @{$item}; # get the original line $line[4] = $id_hash{$line[0]}; # replace the fifth element with th +e calculated maximum print OUT join "\t" ,@line, "\n"; # print the adapted line }

Greetings

Martell

  • Comment on Re^3: for each unique value in a column find the max value..need perl script
  • Download Code

Replies are listed 'Best First'.
Re^4: for each unique value in a column find the max value..need perl script
by qmenon (Initiate) on Jun 01, 2011 at 08:08 UTC

    Thanks Martell, You are right, it does look like it will take time to run it on big data files which is my case; I will give it a go anyways

    .