#!/usr/bin/env perl use strict; use warnings; # ignore lines beginning with: my $regex1 = qr/^\-|^mirrored|^physloc|^svsa|^vtd/i; # beginning of a chunk of interest: my $regex2 = qr/^vhost/i; my $ifil = 'sorted-hoa-input-data.txt'; my %h; # hash to keep client partition IDs open my $fp, '<', $ifil or die "$ifil: $!"; my ($id, $stat, $bd, $lun); while (defined(my $line = <$fp>)) { next if $line =~ m/$regex1/; if ($line =~ m/$regex2/) { my @d = split ' ', $line; $id = $d[2]; } elsif ($line =~ m/^status/i) { my @d = split ' ', $line; $stat = $d[1]; } elsif ($line =~ m/^lun/i) { my @d = split ' ', $line; $lun = $d[1]; } elsif ($line =~ m/^backing\s+device/i) { my @d = split ' ', $line; $bd = $d[2]; if ($stat eq 'Available') { $h{$id}{$bd} = 1; } } } # print the results for my $k (sort keys %h) { print "\n$k\n=>\n"; print "Available\n$_\n" for (sort keys %{$h{$k}}); }