Have some data like the following
Product : CCS
SerialNumber : 75010010
LUs : 2
iLU HDevName OSPathID PathID ChaPort Status Type
0026 hdisk24 00000 000018 1A Online Non
00001 000019 0A Online Own
0148 hdisk29 00000 000020 1A Online Non
00001 000021 0A Online Own
Product : SIP
SerialNumber : 0010111
LUs : 3
iLU HDevName OSPathID PathID ChaPort Status Type
0010 hdisk21 00000 000040 2A Online Own
00001 000041 1A Online Own
0020 hdisk26 00000 000017 1A Online Own
0021 hdisk22 00000 000039 2A Online Own
Product : SIP
...etc
KAPL01001 # ends here
Serial number can either be 8 digits(product CCS) or 7 digits (product SIP) and it is in no particular order
Trying to regex to do 2 things
1) if product is CCS (serial is 8 digits), truncate leading zeros and print
2) if there is a line like so (for other product)
0026 hdisk24 00000 000018 1A Online Non
00001 000019 0A Online Own
then print them together, because they belong together i.e. always grab the following line if we find the first one.
So far I've tried this, and I am getting so frustrated
Any help appreciated.
Product : CCS
SerialNumber : 75010010
LUs : 2
iLU HDevName OSPathID PathID ChaPort Status Type
0026 hdisk24 00000 000018 1A Online Non
00001 000019 0A Online Own
0148 hdisk29 00000 000020 1A Online Non
00001 000021 0A Online Own
Product : SIP
SerialNumber : 0010111
LUs : 3
iLU HDevName OSPathID PathID ChaPort Status Type
0010 hdisk21 00000 000040 2A Online Own
00001 000041 1A Online Own
0020 hdisk26 00000 000017 1A Online Own
0021 hdisk22 00000 000039 2A Online Own
Product : SIP
...etc
KAPL01001 # ends here
Serial number can either be 8 digits(product CCS) or 7 digits (product SIP) and it is in no particular order
Trying to regex to do 2 things
1) if product is CCS (serial is 8 digits), truncate leading zeros and print
2) if there is a line like so (for other product)
0026 hdisk24 00000 000018 1A Online Non
00001 000019 0A Online Own
then print them together, because they belong together i.e. always grab the following line if we find the first one.
So far I've tried this, and I am getting so frustrated
Code:
my $data_file = "myfile.txt";
open DATA, "$data_file" or die "can't open $data_file $!";
while(<DATA>)
{
if (/^Product\s+:\s+CCS/ ... /^Product\s+: \s+(?:CCS|PIS|^KAP)/){
if (/^(\w{4})\s+\w+\s+.*/) {
my $lu = $1;
my $lu =~ s/^0+//;
print "CCS $lu\n";
}
}
elsif (/^Product\s+:\s+PIS/ ... /(?:^KAPL)/){
print "Start of block\n";
if (/^\w{4}\s+\w+\s+.*/) {
print "PIS $_\n";
}
}
}
Any help appreciated.