if there are multiple records in the file only the first is printed.Sure, you did not describe your input data and only gave one sample. I based the suggested program on your data sample. The first sample you gave only had one "CF" line, so I made the first program based on that sample. And it worked.
Then you gave another sample with several "CF" lines (but still only one record block), so I changed my program to fit this new data sample. And it worked.
Now, you're saying that there can be several record blocks. How were we supposed to guess that? Well, in fact, I sort of guessed it would plausibly be the case, but I could not write a program based on an inexistent data sample.
So this is the third version:
And this processes your two record blocks and prints:use strict; use warnings; my $line; while (<DATA>) { if (/^\s*MSISDN=(\d+);/) { print "$line\n" if defined $line; $line = $1 ; } if (/\s*CF=([\w-]+?-(?:NONE|\d+))/) { my $add = $1; $add =~ s{(\d+)$}{1/1/1/$1}; $add =~ s{NONE}{1/1/1/0}; $line .= ",$add"; } } print "$line\n"; __DATA__ # --> Here, the data with two record blocks you presented just above
This is presumably what you want, except for the number at the end of the line, which is discussed just below.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/91436903000 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/91436903000
Also the 91436903000 should be 1/1/1/0-436903000OK, fine, but you're not telling how to derive 436903000 from 91436903000. Should we just remove the first two digits in all cases? Or should we remove 91 when the number starts with 91? Or should we remove any digits until we find 43? Or is it something else? How are we supposed to know if you don't tell us?
So I did not change that, because did not specify the rule to be applied to derive the number you want to print. I guess it is probably fairly easy and you can probably make the change yourself.
In reply to Re^5: Create output from Perl hash
by Laurent_R
in thread Create output from Perl hash
by gbwien
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |