Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Sorting names using Regular Expressions and placing them in different Files.

by Kiran Kumar K V N (Initiate)
on Jan 03, 2007 at 09:43 UTC ( [id://592766]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^2:Sorting names using Regular Expressions and placing them in different Files.
in thread Sorting names using Regular Expressions and placing them in different Files.

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 $!;

Replies are listed 'Best First'.
Re^4: Sorting names using Regular Expressions and placing them in different Files.
by Kiran Kumar K V N (Initiate) on Jan 03, 2007 at 10:10 UTC

    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 $!;

      There is a File <Input>. Following is the data in the Input File :-

      -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 3 02:06 BSC-20041202143000

      -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 4 23:00 BSC-20041204110000

      I can extract this and place the data in corresponding Output File viz.:- BSC. The O/P in File BSC is also shown as :-

      -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 3 02:06 BSC-20041202143000

      -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 4 23:00 BSC-20041204110000

      Now how do I get the following Output from the same above Input File :-

      -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 3 02:06 BSC-20041202143000 -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 3 02:06 20041202143000

      -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 4 23:00 BSC-20041204110000 -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 4 23:00 20041204110000

      How should I go about it ??

        What are you trying to do?

        All I can see is repeated lumps of this data:

        -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 3 02:06 BSC-20041202143000 -rw-rw-rw- 1 bsmbin bsmbin 303 Dec 4 23:00 BSC-20041204110000

        What transformation are you trying to effect, if any?

        Alex / talexb / Toronto

        "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://592766]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.