Hello gbwien,
Maybe this is not the best solution to your problem but it could be a point of start:
#!/usr/bin/perl use strict; use warnings; use feature 'say'; open (my $fhIn, '<', "in.txt") or die "Can not open 'in.txt': $!"; open (my $fhOut, '>', "out.txt") or die "Can not open 'out.txt': $!"; my %hash; my $count = 0; while (<$fhIn>) { chomp; if (/<SUBBEGIN/) { $count = 1; } elsif (/<SUBEND/) { $count = 0; } elsif ($count) { my @tmp = split /=/; chop $tmp[1]; if (/MSISDN/) { $hash{MSISDN} = $tmp[1]; } elsif (/ODBIC/) { $hash{ODBIC} = $tmp[1]; } elsif (/ODBOC/) { $hash{ODBOC} = $tmp[1]; } } if ($count == 0) { if (exists $hash{MSISDN}) { say $fhOut "Update Command <".$hash{MSISDN}.">,".$hash{ODBIC}. +",".$hash{ODBOC}.""; } else { say $fhOut "Update Command MSISDN=notSet,".$hash{ODBIC}.",".$h +ash{ODBOC}.""; } delete $hash{MSISDN}; delete $hash{ODBIC}; delete $hash{ODBOC}; } } close ($fhIn) or warn "Could not close 'in.txt': $!"; close ($fhOut) or warn "Could not close 'out.txt': $!"; __END__ $ cat out.txt Update Command <123476789678>,BIC,BAOC Update Command MSISDN=notSet,BIC,BAOC
If there is something that you can not understand let me know. Maybe you will find other ways to approach your problem at Getting lines in a file between two patterns.
Hope this helps, BR.
In reply to Re: Grouped Regular Expression not set assign default value
by thanos1983
in thread Grouped Regular Expression not set assign default value
by gbwien
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |