in reply to Sorting a (very) large file
#!/usr/bin/perl use strict; use warnings; my %data; my $file = $ARGV[0] or die "Usage: $0 <input_file>"; open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $ +!"; my $pos = tell $fh; while (<$fh>) { my $size = (split /\t/)[2]; $data{$size} = exists $data{$size} ? $data{$size} . ":$pos" : $pos; $pos = tell $fh; } for my $size (sort {$b <=> $a} keys %date) { for my $pos (split /:/, $data{$size}) { seek($fh, $pos, 0); my $line = <$fh>; print $line; } }
Note: This code is untested an is not optimal. It was just an idea I had that you might want to try. It will output lines of files with the same size in the same order they appeared in the original file.
Cheers - L~R
|
|---|