- 论坛徽章:
- 307
|
- #!/usr/bin/perl
- use strict;
- use warnings;
- my %hData = ();
- while(<DATA>){
- last if(/\A\s*\z/);
- chomp;
- my ($host, $ip, $mac) = split(/\s*;\s*/);
- foreach my $dev ('FULL', $ip, $mac){
- $dev ||= 'NULL';
- $hData{$host}{$dev} = $dev eq 'FULL' ? $_ : 1;
- }
- }
- while(<DATA>){
- chomp;
- my ($host, $ip, $mac, $other) = split(/\s*;\s*/);
- $host =~ s/\..*//;
- if(exists($hData{$host})){
- print("$hData{$host}{'FULL'}; $other\n");
- next;
- }
- foreach my $hhost (keys %hData){
- next if(!$hData{$hhost}{$ip} or !$hData{$hhost}{$mac});
- print("$hData{$hhost}{'FULL'}; $other\n");
- last;
- }
- }
- __DATA__
- host1 ; ip1 ; mac1
- host2 ; ip2 ;
- host3 ; ; mac3
- host4 ; ip4 ; mac4
- host1.xx.xx.x ; ip1 ; mac1 ; winpc
- host2.xx.xx.x ; ip2 ; mac2 ; linuxpc
- host3.xx.xx.x ; ip3 ; mac3 ; linuxpc
- host5.xx.xx.x ; ip5 ; mac5 ; winpc
- host5.xx.xx.x ; ip4 ; mac4 ; winpc
复制代码 perl abc.pl
------------------------------------
host1 ; ip1 ; mac1; winpc
host2 ; ip2 ;; linuxpc
host3 ; ; mac3; linuxpc
host4 ; ip4 ; mac4; winpc
|
|