in reply to Re: Grouped Regular Expression not set assign default value
in thread Grouped Regular Expression not set assign default value
Hi thanos1983 Thank you for your help, I extended your solution to check for these fields CF and ODB fields which I output to a comma separated file when set and not set. It works fine except for CF fields, I think this is because these lines are not unique in the file. For CF lines example I would like to set CfuNotSet if the line CFU-ALL-PROV-NONE is not found, CFbNoSet if the line CFB-ALL-PROV-NONE is not found and so on. Eventually I would also like to check for CB fields. I have done this without a hash with the help from Laurent_R but I would like to learn your solution too
This piece of code seems ok code
#build up the hash CF if (/CF/){ $hash{CF} = $tmp[1]; #say $hash{CF}; }
I think the problem is here
#PROBLEM CODE check CF fields need to accommodate for multiple CF l +ines if (exists $hash{CF}) { $add = $hash{CF}; $line .= ",$add"; }
<BEGINFILE> <SUBBEGIN IMSI=11111111111111; MSISDN=431234567893; CB=BAOC-ALL-PROV; CB=BOIC-ALL-PROV; CB=BOICEXHC-ALL-PROV; CB=BICROAM-ALL-PROV; IMEISV=4565676567576576; CW=CW-ALL-PROV; CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-NO +-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N +O-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO +-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 <SUBBEGIN IMSI=11111111111133; MSISDN=431234567899; 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-NO +-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N +O-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO +-NO-NO-NO; CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFU-TS10-ACT-914369050045021-YES-NO-NONE-YES-65535-YES-YES-NO-N +O-NO-NO-NO-NO-NO-NO; CF=CFD-TS10-REG-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO- +YES-YES-YES-YES-NO; ODBIC=BICCROSSDOMESTIC; ODBOC=BAOC; ODBROAM=ODBOH; ODBPRC=INFO; ODBPLMN=PLMN1 ODBPLMN=PLMN3; ODBPOS=NOBPOS-BOTH; ODBECT=OdbAllECT; ODBDECT=YES; ODBMECT=YES; ODBPREMSMS=NO; ODBADULTSMS=YES; <SUBEND
If I understand it correctly you split up the lines of the record based on the equals sign. This seems to work fine until CF entries are encountered
#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; my $HSSIN='D:\testproject\HSS-export.txt'; my $ofile = 'D:\testproject\HSS-output-withhash.txt'; open (INFILE, $HSSIN) or die "Can't open input file"; open (OUTFILE,"> $ofile" ) or die "Cant open file"; my %hash; my $count = 0; my $add; my $line; while (<INFILE>) { chomp; next if /^<ENDFILE>/; next if /^<BEGINFILE>/; if (/<SUBBEGIN/) { $count = 1; } elsif (/<SUBEND/) { $count = 0; } elsif ($count) { my @tmp = split /=/; chop $tmp[1]; #build up the hash CF if (/CF/){ $hash{CF} = $tmp[1]; #say $hash{CF}; } if (/MSISDN/) { $hash{MSISDN} = $tmp[1]; } if (/ODBIC/) { $hash{ODBIC} = $tmp[1]; } elsif (/ODBOC/) { $hash{ODBOC} = $tmp[1]; } elsif (/ODBROAM/) { $hash{ODBROAM} = $tmp[1]; } } if ($count == 0) { #check MSISDN field if (exists $hash{MSISDN}) { $line = $hash{MSISDN}; #'say OUTFILE $line; #say OUTFILE "Update Command <".$hash{MSISDN}.">,".$hash{ODBIC +}.",".$hash{ODBOC}.",".$hash{ODBROAM}.""; } else { #say OUTFILE "Update Command MSISDN=notSet,".$hash{ODBIC}.",".$ +hash{ODBOC}.""; $line = 'MSISDN=notSet'; } #PROBLEM CODE check CF fields need to accommodate for multiple CF l +ines if (exists $hash{CF}) { $add = $hash{CF}; $line .= ",$add"; } #check ODBIC field if (exists $hash{ODBIC}) { $add = $hash{ODBIC}; $line .= ",$add"; } else { $add = 'ODBICnotSet'; $line .= ",$add"; } #check ODBOC field if (exists $hash{ODBOC}) { $add = $hash{ODBOC}; $line .= ",$add"; } else { $add = 'ODBOC notSet'; $line .= ",$add"; } #check ODBROAM field if (exists $hash{ODBROAM}) { $add = $hash{ODBROAM}; $line .= ",$add"; } else { $add = 'ODBROAM notSet'; $line .= ",$add"; } #check hash for ODBOC->BAOC is not set set it to ODBOC->BAOCnotSet delete $hash{MSISDN}; delete $hash{ODBIC}; delete $hash{ODBOC}; delete $hash{ODBROAM}; delete $hash{CF}; #build up line say OUTFILE $line; } } close INFILE; close OUTFILE;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Grouped Regular Expression not set assign default value
by thanos1983 (Parson) on Feb 22, 2018 at 15:22 UTC | |
by gbwien (Sexton) on Feb 23, 2018 at 12:16 UTC | |
by thanos1983 (Parson) on Feb 23, 2018 at 15:42 UTC | |
by Anonymous Monk on Feb 23, 2018 at 19:49 UTC |