G'day baxy77bax,
Without knowing the (average) record size, it's a little hard to estimate whether this solution fits the 100MB memory limit. If the records are of a similar size to your dummy data, then it probably won't meet that requirement; if they are in the order of hundreds bytes each, then you may be in with a chance.
Anyway, here's the potential solution [Updated - see below]:
$ perl -Mstrict -Mwarnings -Mautodie -le ' use Tie::File; tie my @input_records, "Tie::File", "./pm_1054101_input.txt"; open my $out_fh, ">", "./pm_1054101_output.txt"; print $out_fh $input_records[$_] for map { $_->[0] } sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] } map { [ $_, map { substr $_, 3 } (split " ", $input_records[$_ +])[0,1] ] } 0 .. $#input_records; close $out_fh; untie @input_records; '
Input file:
$ cat pm_1054101_input.txt key1 key2 ndnjfgdsjfjjkjjfjf... key1 key2 kdfkjdfgdfugbjndkfgkjgndkjfjkd key43 key21 sdkjfhdghdbgbd key1 key3 jujdejnsduhffnjj key2 key2 jhzezhdjjf...
Output file:
$ cat pm_1054101_output.txt key1 key2 ndnjfgdsjfjjkjjfjf... key1 key2 kdfkjdfgdfugbjndkfgkjgndkjfjkd key1 key3 jujdejnsduhffnjj key2 key2 jhzezhdjjf... key43 key21 sdkjfhdghdbgbd
File sizes unchanged:
$ ls -l pm_1054101_* -rw-r--r-- 1 ken staff 159 14 Sep 22:41 pm_1054101_input.txt -rw-r--r-- 1 ken staff 159 14 Sep 23:04 pm_1054101_output.txt
Update: I removed an intermediary array which might save some memory. Here's the original code:
-- Ken
In reply to Re: sorting type question- space problems
by kcott
in thread sorting type question- space problems
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |