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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |