The program I suggested used the MSISDN line to detect the beginning of a new block. This has to be changed if the MSISDN line can be absent from a record block. Here I changed the end block detection to matching <SUBEND, which simplifies a bit the code. Otherwise, we initialize a new line with "MSISDN=0" and change it to the MSISDN value if we find a MSISDN line. That's how it looks after these changes:
use strict;
use warnings;
use strict;
use warnings;
my $line = "MSISDN=0";
while (<DATA>) {
if (/<SUBEND/) {
print "$line\n";
$line = "MSISDN=0";
}
$line = $1 if /^\s*MSISDN=(\d+);/;
if (/\s*CF=([\w-]+?-(?:NONE|\d+))/) {
my $add = $1;
$add =~ s{\d\d(\d+)$}{1/1/1/$1};
$add =~ s{NONE}{1/1/1/0};
$line .= ",$add";
}
}
__DATA__
<BEGINFILE>
<SUBBEGIN
IMSI=232191400010332;
MSISDN=436906901235;
CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N
+O-NO-NO;
CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-
+NO-NO-NO;
CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-N
+O-NO-NO-NO;
CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO
+-NO-NO-NO;
CF=CFD-TS10-ACT-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO
+-YES-YES-YES-YES-NO;
<SUBEND
<BEGINFILE>
<SUBBEGIN
IMSI=232191400010339;
MSISDN=436906901231;
CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N
+O-NO-NO;
CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-
+NO-NO-NO;
CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-N
+O-NO-NO-NO;
CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO
+-NO-NO-NO;
CF=CFD-TS10-ACT-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO
+-YES-YES-YES-YES-NO;
<SUBEND
<SUBBEGIN
IMSI=232191400010339;
CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N
+O-NO-NO;
CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-
+NO-NO-NO;
CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-N
+O-NO-NO-NO;
CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO
+-NO-NO-NO;
CF=CFD-TS10-ACT-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO
+-YES-YES-YES-YES-NO;
<SUBEND
This prints the following output:
$ perl msisdn.pl
436906901235,CFU-ALL-PROV-1/1/1/0,CFB-ALL-PROV-1/1/1/0,CFNRY-ALL-PROV-
+1/1/1/0,CFNRC-ALL-PROV-1/1/1/0,CFD-TS10-ACT-1/1/1/436903000
436906901231,CFU-ALL-PROV-1/1/1/0,CFB-ALL-PROV-1/1/1/0,CFNRY-ALL-PROV-
+1/1/1/0,CFNRC-ALL-PROV-1/1/1/0,CFD-TS10-ACT-1/1/1/436903000
MSISDN=0,CFU-ALL-PROV-1/1/1/0,CFB-ALL-PROV-1/1/1/0,CFNRY-ALL-PROV-1/1/
+1/0,CFNRC-ALL-PROV-1/1/1/0,CFD-TS10-ACT-1/1/1/436903000
which seems to be what you're looking for.
Update: changed my $line; to my $line = "MSISDN=0"; following AnomalousMonk's correct comment in Re^15: Create output from Perl hash. Thanks to AnomalousMonk for that.
|