in reply to Re^4: Print to specific line
in thread Print to specific line

If, as I suspect, the OP does not want the numbers to print:

use strict; use warnings; my (%hash); while (<>) { chomp; my ($text,$line) = $_ =~ m/(.+)(\d+)$/; $hash{$line} = $text; } print $hash{$_} . "\n" for (sort keys %hash)

Since I use only the keys, no worries about missing line numbers.

Usage:

perl pm1.pl < input.txt > output.txt

Update: I along with other respondents missed the fact that there could potentially be non-sequential line numbers in the data, and there might need to be blank lines created accordingly. Updated again to be a bit more perlish.

use strict; use warnings; my (@array); while (<>) { $array[$2] = 1 if ($_ =~ m/(.+)(\d+)$/) } print defined $_ ? $_ . "\n" : "\n" for @array[1..$#array];
Dum Spiro Spero