Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
"be consistent"
 
PerlMonks  

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

by santhi (Monk)
on Dec 28, 2006 at 23:58 UTC ( [id://592169]=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: Sorting names using Regular Expressions and placing them in different Files.
in thread Sorting names using Regular Expressions and placing them in different Files.

I think you need to move the files that start with BSC, SBSCSubsytem and MCBTSSubSystem into separate directories.

1. Create the separate directories for BSD, SBSCSubsystem and MCBTSSubsytem under the directory you want to search or at nay other path
chdir("test") ## For eg:test can be directory where the files exist. unless (-d "BSD"){ mkdir("BSD") or warn ("unable to create directory BSD"); } unless (-d "SBSCSubsystem"){ mkdir("SBSCSubsystem") or warn ("unable to create directory SBSCSu +bsystem"); } unless (-d "MCBTSSubsytem"){ mkdir("MCBTSSubsytem") or warn ("unable to create directory MCBTSS +ubsytem"); }
Get the lsit of files that matches the BSD, MCBTSSubsytem etc into separate arrays.
opendir(DIR, "test") @files_BSD = grep(/^BSD-\d{14}/, readdir(DIR)); @files_SBSC = grep(/^SBSCSubsystem-\d{14}/, readdir(DIR)); @files_MCBTS = grep(/^MCBTSSubsytem-\d{14}/, readdir(DIR));
Then move the files into respective directories.
foreach (@files_BSD){ rename($_, "BSD/$_" ); } foreach (@files_SBSC){ rename($_, "SBSCSubsystem/$_"); } foreach (@files_MCBTS){ rename($_, "MCBTSSubsytem/$_"); }

Replies are listed 'Best First'.
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

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

      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 ??

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://592169]
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.