#usr/bin/perl use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("vrrp.xls"); my $worksheet = $workbook->add_worksheet(); $worksheet->write ("A1", 'Device'); $worksheet->write ("B1", 'Interface Name'); $worksheet->write ("C1", 'VRID'); $worksheet->write ("D1", 'State'); $worksheet->write ("E1", 'Primary ip address'); $worksheet->write ("F1", 'VRRP Address'); my $row = 2; my $line = ''; my $device; open inFile, '<', 'svrrp.txt' or die "Couldn't open svrrp.txt: $!"; while (! eof inFile) { $line .= ' ' . ; chomp $line; next if ! ($line =~ /logging\sto\sDevice\s(.*?)\s+/i) and ! eof inFile; my $nextDevice = $1; next if ! ($line =~ /Interface\s(.*?)\s+/i) ; my $nextInterface = $1; #next if ! ($line =~ /Interface\s(.*?)\s+/i) ; #my $nextInterface = $1; { if ($line=~ m[ (?=.*? nterface \s+ (\S+) ) (?=.*? VRID \s+ (\S+) ) (?=.*? State: \s+ (\S+) ) (?=.*? Primary\saddress: \s+ (\S+) )]smx) { $worksheet->write("A$row", "$device"); $worksheet->write("B$row", "$1"); $worksheet->write("C$row", "$2"); $worksheet->write("D$row", "$3"); $worksheet->write("E$row", "$4"); my (@ip)=($line=~m/number addresses(?:.*?)((?:\d{1,3}\.){3}\d{1,3})/gsi); print "The addresses are: ". join("\n",@ip)."\n\n"; print " end\n\n"; $worksheet->write("F$row", join("\n",@ip)); ++$row; } else { print "no match found\n" ; } print "$device,$Interface,$1, $2, $3, $4 \n"; } $Interface = $nextInterface; ++$row; $device = $nextDevice; $line = " "; } close inFile; $workbook->close();