Perl to the rescue:
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
my @lines = <DATA>;
my @newlines =
map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { [ ((/(\d{4})/) ? $1 : 0), $_ ] }
@lines;
print $_ foreach @newlines;
__DATA__
1945 was the year World War 2 ended.
Battle of Hastings: 1066.
This line does not have a number.
In 1492 America was discovered by a european - again.
Output:
Code:
This line does not have a number.
Battle of Hastings: 1066.
In 1492 America was discovered by a european - again.
1945 was the year World War 2 ended.
Bookmarks