The following updated Code extracts all the

filenames with the data <FileName>-**************

(Filename being ‘BSC’,‘SBSCSubsystem’,

‘MCBTSSubsystem’),in the given list of Filenames

in the Input File ‘bsm1_LogFiles’and place

corresponding appropriate Filenames in the Output

Files created viz. ‘BSC’, ‘SBSCSubsystem’ and

‘MCBTS’, respectively. The below updated Script

gives the appropriate Output when the command

“perl –w Test.pl” is executed from the Root :-

 #!/usr/bin/perl -w  use strict;

## Open I/P File "bsm1_LogFiles" for reading.

    open(INPUT,'<','bsm1_LogFiles') or die $!;

## Read from the Input File.

    my $line  = <INPUT>;

## Open the O/P File "BSC" for writing.

    open(BSC,'>','BSC') or die $!;

## Open the O/P File "SBSCSubsystem" for writing.

  open(SBSCSubsystem,'>','SBSCSubsystem') or die $!;

## Open the O/P File "MCBTSSubsystem" for writing.

open(MCBTSSubsystem,'>','MCBTSSubsystem')or die $!;

## Search each Line in the Input File.

      for my $searchline(<INPUT>) {

## Search for parameter 'BSC-'.

           if( $searchline =~ /BSC-/) {

## Write to the Output File 'BSC'.

                my $line  = 'BSC';                 print BSC $searchline;                                       }

## Search for parameter 'SBSCSubsystem-'.

           elsif( $searchline =~ /SBSCSubsystem-/) {

## Write to Output File 'SBSCSubsystem'.

               my $line  = 'SBSCSubsystem';                print SBSCSubsystem $searchline;                                                    }

## Search for parameter 'MCBTSSubsystem-'.

          if( $searchline =~ /MCBTSSubsystem-/) {

## Write to Output File 'MCBTSSubsystem'

               my $line  = 'MCBTSSussystem';                 print MCBTSSubsystem $searchline;                                                 }                               }

## Close the O/P File "BSC";

    close (BSC) or die $!;

## Close the O/P File "SBSCSubsystem";

    close (SBSCSubsystem) or die $!;

## Close the O/P File "MCBTSSubsystem";

    close (MCBTSSubsystem) or die $!;

In reply to Re^3: Sorting names using Regular Expressions and placing them in different Files. by Kiran Kumar K V N
in thread Sorting names using Regular Expressions and placing them in different Files. by Kiran Kumar K V N

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.