Sort a list of reverse lookups while ignoring the header perl
I have a list.
27 IN PTR conf.
27 IN PTR test.
250 IN PTR testbed1.
251 IN PTR testbed2.
55 IN PTR t.
48 IN PTR nagios.
49 IN PTR cacti-01.
29 IN PTR vmwlinux01.
22 IN PTR regserver.
6 IN PTR grpwise.
18 IN PTR blah.
28 IN PTR srver.
60 IN PTR aiscons2.
45 IN PTR digg.
1 IN PTR ip-3-.
2 IN PTR ip-3-.
This list has a header that is 15 lines long. I would like to sort this list by the number on the left, smallest to largest.
Hopefully, I would end up with a list like this
header ~~~~~~~~~~
1 IN PTR ip-3-.
2 IN PTR ip-3-.
6 IN PTR grpwise.
18 IN PTR blah.
22 IN PTR regserver.
27 IN PTR conf.
27 IN PTR test.
28 IN PTR srver.
29 IN PTR vmwlinux01.
45 IN PTR digg.
48 IN PTR nagios.
49 IN PTR cacti-01.
55 IN PTR t.
60 IN PTR aiscons2.
250 IN PTR testbed1.
251 IN PTR testbed2.
I do not know where to begin to code this. I thought of using tail -n $lc $f开发者_C百科ile | sort -g
where $lc is the number of lines minus the header, and $file is the file to sort.
Any suggestions?
Thanks
BTW, I have changed the names for security reasons.
If the file is not very large, you can read it into an array and sort lines numerically:
open my $fh, '<', $file or die $!;
my @lines = <$fh>;
print @lines[0..14]; # the header
print sort { $a <=> $b } @lines[15..$#lines];
精彩评论