in reply to Sorting a (very) large file

condar,
There have been some ideas already from the chatterbox. Here is an idea that I had while I was thinking about it:
#!/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

Inlined get_size() sub which was just a call to split. Also specified keys %date