1
2
3
4
5
6
7
8
9
x.x.x.1 host1.de
x.x.x.1 host1.de
x.x.x.1 host1.de
x.x.x.1 host1.de host1
x.x.x.2 host2 host2.de
x.x.x.2 host2 host2.de
x.x.x.2 host2.de host2
x.x.x.2 host2.de
x.x.x.2 host2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#! /usr/bin/perl use strict; use warnings; my %hash; while ( my $line = <DATA> ) { my ( $ip, @names ) = map { defined $_ ? $_ : () } split /\s+/, $line; for my $name ( @names ) { $hash{$ip}->{$name} = 1; } } # Ausgabe; die sort-Anweisungen können/sollten noch verfeinert werden for my $ip ( sort keys %hash ) { print "$ip\t", join( ' ', reverse sort keys %{$hash{$ip}} ), "\n" } __DATA__ x.x.x.1 host1.de x.x.x.1 host1.de x.x.x.1 host1.de x.x.x.1 host1.de host1 x.x.x.2 host2 host2.de x.x.x.2 host2 host2.de x.x.x.2 host2.de host2 x.x.x.2 host2.de x.x.x.2 host2