Hi List
I have a data file as with the following format

<RRPTP:PSTU=ALL;
RADIO TRANSMISSION PACKET SWITCHED TERMINATION UNIT DATA

PSTU                  STN                 IWDVER
AGMOU1SIU_DD3045      AGMOU1SIU           3

SAPI  LBG  CONN
 0      1  ACT
10      1  ACT
11      1  ACT
12      1  ACT
62      1  ACT

PSTU                  STN                 IWDVER
AIRMA1SIU_DD0190      AIRMA1SIU           3

SAPI  LBG  CONN
 0      1  ACT
10      1  ACT
11      1  ACT
12      1  ACT
62      1  ACT

PSTU                  STN                 IWDVER
ALCAC1SIU_DD3872      ALCAC1SIU           3

SAPI  LBG  CONN
 0      1  ACT
10      1  ACT
11      1  ACT
12      1  ACT
62      1  ACT

END
## I was told that this data file has a fixed format so   to parse this
data file I have developed the following code and this is working fine.

open my $RFH,'<',$Input_File_Name;
open my $WFH,'>',$Output_File_Name;
my $str;
my $print_flag = 'N';
my $print_flag_1 = 'N';

            while(<$RFH>) {
                    if ($print_flag eq 'Y') {
                        my $line = $_;
                        chomp($line);
                        my @line_1  = split(/\s+/,$line);
                        if(($line_1[1]) && ($line_1[2])) {
                            my $str_tmp_1 =
"$line_1[0];$line_1[1];$line_1[2];";
                            $str .= $str_tmp_1;
                        }else {
                            my $str_tmp_1 = "$line_1[0];NULL;NULL;";
                            $str .= $str_tmp_1;
                        }
                        $print_flag = 'N';
                        }
            $print_flag = 'Y' if m/^PSTU/;

            if ($print_flag_1 eq 'Y') {
                            my $line = $_;
                            chomp($line);
                            $line =~ s/^\s+//g;

                            my $number = substr($line,0,2);
                            if( $number =~ m/\s{1}0/ ) {
                                $str .= "1;";
                            }

                            if( $number =~ m/10/ ) {
                                $str .= "1;";
                            }

                            if( $number =~ m/11/ ) {
                                $str .= "1;";
                            }

                            if( $number =~ m/12/ ) {
                                $str .= "1;";
                            }

                            if( $number =~ m/62/ ) {
                                $str .= "1";
                                print $WFH "$str\n";
                                $str = "";
                                $print_flag_1 = 'N';
                            }

                    }
                    $print_flag_1 = 'Y' if m/^\s*$/;
                    #$print_flag_1 = 'Y' if m/^PSTU/;
            }
            close($RFH);
            close($WFH);
    }

But now the data file has changed into the following format ( To make it
short I am copying here part of it)

SAPI  LBG  CONN
10      1  ACT
11      1  ACT
12      1  ACT

(There is a change in the SAPI section , PSTU will be remain same )
Now they are saying that it can be possible that  all  SAPI will not be
present at a time ( which are 0,10,11,12,62) . As you can see 0 and 62 are
missing in this case.
Out of five SAPI any number can be present in a SAPI block.
So I am trying to write a generic code which can handle the data/lines
starting below the SAPI upto the next blank line , so in the above case it
will be from stating from 10 upto 12.

Can you please provide me any idea how to do this?

Best Regards
Anirban.

Reply via email to