use strict; use warnings; sub prettyip { my $ip = shift; $ip =~ s/ (\d+) / sprintf("%03d",$1) /smgex; return $ip; } my %last_seen_ip_from_hop; # last IP seen for key=HOP my $section = 1; # section within the file my $previous_hop = 0; # previous HOP / new section event while (my $line = ) { if ($line =~ /^(\d+),(\S+)/) { # extract HOP and IP my ($hop, $ip) = ($1, $2); my $last_ip_seen = $last_seen_ip_from_hop{$hop}; my ($changemark_pre, $changemark_pos) = ("", ""); # detect a new section (A/B/C) $section++, print "\n" if $previous_hop > $hop; # new file/section $previous_hop = $hop; # notify if a change occured for a given hop since last seen if (defined $last_ip_seen and $ip ne $last_ip_seen) { $changemark_pre = 'changed to'; $changemark_pos = '(was: ' . prettyip($last_ip_seen) . ')'; } $last_seen_ip_from_hop{$hop} = $ip; # init or update current HOP/IP printf "sect.%2d / hop %2d: %15s %15s %s\n", $section, $hop, $changemark_pre, prettyip($ip), $changemark_pos; } } __DATA__ 13,4.69.137.70 14,4.69.134.70 15,4.69.134.113 16,4.69.135.185 17,4.69.134.246 18,4.68.18.75 19,4.59.0.10 20,124.211.34.129 21,203.181.100.61 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11 13,4.69.137.74 14,4.69.134.70 15,4.69.134.113 16,4.69.135.185 17,4.69.134.246 18,4.68.18.11 19,4.59.0.10 20,124.211.34.121 21,203.181.100.61 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11 13,4.69.137.70 14,4.69.134.78 15,4.69.134.125 16,4.69.135.185 17,4.69.134.250 18,4.68.18.139 19,4.59.0.10 20,124.211.34.121 21,203.181.100.189 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11