Hi Laurent_R
Thanks again for your help. The code I wrote in http://www.perlmonks.org/?node_id=1209586 is based on the same problem but I made the mistake of not using a consistent input file across posts. I am still working on building up the contents of the input file with additional populated data and I thought it was best to use something like <SUBBEGIN and <SUBEND. Additional populated data below to be decided is represented by ..... and may appear anywhere in the file,but I don't need to worry about this. For the output file I am only interested in extracting and checking the fields MSISDN, CB, CF, ODB based on what is to the right of the equals sign. Also one important point the data may appear in any order.
My question in the last post was to try to understand how to check if the line MSISDN is not found . I thought I could apply this knowledge to lines CB, CF and ODB too and wirte something similar e.g. CB=BAOC-ALL-PROV; not found write CBBocallProvNotSet, CF=CFU-ALL-PROV-NONE not found write CFUallProvNotSet.
Again very sorry about the confusion, I will try to be more concise on the site going forward
Example record in the input file with all considered values we spoke about
<SUBBEGIN
IMSI=21111111111111;
MSISDN=413333333331;
.....
...
CB=BAOC-ALL-PROV;
CB=BOIC-ALL-PROV;
CB=BOICEXHC-ALL-PROV;
CB=BICROAM-ALL-PROV;
CW=CW-ALL-PROV;
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;
ODBIC=BAIC;
ODBOC=BAOC;
ODBROAM=ODBOHC;
ODBPRC=ENTER;
ODBPRC=INFO;
ODBPLMN=NONE;
ODBPOS=NOBPOS-BOTH;
ODBECT=OdbAllECT;
ODBDECT=YES;
ODBMECT=YES;
ODBPREMSMS=YES;
ODBADULTSMS=YES;
<SUBEND
I wrote the following based on your code
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
my $HSSIN='D:\testproject\HSS-export.txt';
my $ofile = 'D:\testproject\HSS-output.txt';
my $add;
my $MSISDN;
open (INFILE, $HSSIN) or die "Can't open input file";
open (OUTFILE,"> $ofile" ) or die "Cant open file";
my $line;
while (<INFILE>) {
if (/<SUBEND/) {
print OUTFILE "$line\n";
$line = "MSISDN=0";
}
$line = $1 if /^\s*MSISDN=(\d+);/;
#if (/^\t*MSISDN=(\d+);/) { #find MSISDN in file global search
# print OUTFILE "processSingle Update Command MKEY <parameter n
+ame> $line, \n" if defined $line;
# $line = "<$1>"; #group 1
#blockings
if (/\t*CB=([\w-]+?);/)
{
$add = $1;
$line .= ",$add";
}
#call forwardings
if (/\t*CF=([\w-]+?-(?:NONE|\d+))/ and (!/(\t*CF=CFD-[\w-]+?-\d+)/
+))
{
$add = $1; #the entire of group 1 above, next search the line
$add =~ s/\t//g;
$add =~ s/(91)(\d+)?/$2/; #remove 91 from $1 above CFD-TS10-AC
+T-91436903000
#$add =~ s/\b436903000/43660303060/;
$add =~ s/(\d+)$/1\/1\/1\/$1/;
$add =~ s/NONE/1\/1\/1\/0/;
$line .= ",$add";
}
#change CFD to 43660303060 for voicemail
if (/(\t*CF=(CFD-[\w-]+?-\d+))/ )
{
$add = $2;
$add =~ s/\t//g;
#$add =~ s/(91)(\d+)?/1\/1\/1\/$2/; #remove 91 from $2 above
$add =~ s/\b91436903000/1\/1\/1\/43660303060/;
$add =~ m/(?:CFD-[\w].*-)(\d)\/(\d)\/(\d)\/(\d*)/;
$line .= ",$add";
}
#odb stuff
#if ($_ =~ m/\t*ODBIC=([\w-]+?\w.*);/)
if (/\t*ODBIC=([\w]+?\w.*);/)
{
#$add = "mappedBICVALUE";
$add = $1,
$line .= ",$add";
}
if (/\t*ODBOC=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBROAM=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBPRC=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBPLMN=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBPOS=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBECT=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBDECT=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBMECT=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBPREMSMS=([\w]+?\w.*);/)
{
$add = $1;
$line .= ",$add";
}
if (/\t*ODBADULTSMS=([\w]+?\w.*);/)
{
$add = "$1";
$line .= ",$add";
}
#if (/\t*ODB(\w+)?=([\w-]+?\w.*);/)
#{
# $add = $2;
#$add =~ s/\t//g;
# $line .= ",$add";
#}
}
#print OUTFILE "processSingle Update Command MKEY <parameter name> $li
+ne, \n";
close INFILE;
close OUTFILE;
|