[aklug] Re: perl lists question, sorting, sort of.

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Tue Aug 17 2010 - 13:13:21 AKDT

On Tue, 17 Aug 2010, Arthur Corliss wrote:

> perl -ane '$ip{$F[0]} .= " $F[1]"; END { foreach (keys %ip) {
> print "$_ $ip{$_}\n" }; };' /etc/hosts

It occurred to me that you might already have a few lines in your hosts file
with multiple names on one line. The following alternative will preserve
those extra host names as well:

   perl -ane '$ip{$F[0]} = join " ", $ip{$F[0]}, @F[1 .. $#F];
     END { foreach (keys %ip) { print "$_ $ip{$_}\n" }; };'

         --Arthur Corliss
           Live Free or Die
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Aug 17 13:13:30 2010

This archive was generated by hypermail 2.1.8 : Tue Aug 17 2010 - 13:13:30 AKDT