Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl Monk, Perl Meditation
 
PerlMonks  

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

by Kiran Kumar K V N (Initiate)
on Dec 28, 2006 at 13:41 UTC ( [id://592121]=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^6: Sorting names using Regular Expressions and placing them in different Files.
in thread Sorting names using Regular Expressions and placing them in different Files.

Hi All,

I am a real real beginner of Perl.

I am trying to write a Perl Script to extract all the filenames with the date <FileName>.20041204****** in the given list of Filenames as below and place BSC, SBSCSubsystem and MCBTS filenames in separate files:

-rw-rw-rw- 1 bsmbin bsmbin 0 Dec 3 00:31 arun2-20041127120100

-rw-rw-rw- 1 bsmbin bsmbin 0 Dec 3 00:31 abc2-20041127130812

-rw-rw-rw- 1 bsmbin bsmbin 0 Dec 3 00:31 abc1-20041127131046

-rw-rw-rw- 1 bsmbin bsmbin 10065 Dec 3 02:06 SBSCSubsystem-20041202143000

-rw-rw-rw- 1 bsmbin bsmbin 10065 Dec 3 02:06 SBSCSubsystem-20041202140000

-rw-rw-rw- 1 bsmbin bsmbin 10065 Dec 3 02:06 SBSCSubsystem-20041202133000

-rw-rw-rw- 1 bsmbin bsmbin 7018 Dec 3 02:06 MCBTSSubsystem-20041202143000

-rw-rw-rw- 1 bsmbin bsmbin 7019 Dec 3 02:06 MCBTSSubsystem-20041202140000

-rw-rw-rw- 1 bsmbin bsmbin 7020 Dec 3 02:06 MCBTSSubsystem-20041202133000

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

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

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

-rw-rw-rw- 1 bsmbin bsmbin 10065 Dec 3 03:00 SBSCSubsystem-20041202150000

-rw-rw-rw- 1 bsmbin bsmbin 7020 Dec 3 03:00 MCBTSSubsystem-20041202150000

-rw-rw-rw- 1 bsmbin bsmbin 303 Dec 3 03:00 BSC-20041202150000

-rw-rw-rw- 1 bsmbin bsmbin 10065 Dec 3 04:00 SBSCSubsystem-20041202160000

-rw-rw-rw- 1 bsmbin bsmbin 10065 Dec 3 04:00SBSCSubsystem-20041202153000

The Algorithm I thought of is like this :-

1) Create 3 separate Files with names BSC, SBSCSubsystem and MCBTSSubsystem using File I/O.

2) First, check in the given list of filenames starting from the top, files with name BSC-20041202******. For each filename found/sorted out in this Format, move the corresponding filename to the File BSC.Continue this process, until you reach the end of the List.

3) Second, check in the given list of filenames starting from the top, files with name SBSCSubsystem- 20041202******. For each filename found/sorted out in this Format, move the corresponding filename to the File SBSCSubsystem. Continue this process, until you reach the end of the List.

4) Third, check in the given list of filenames starting from the top, files with name MCBTSSubsystem- 20041202******. For each filename found/sorted out in this Format, move the corresponding filename to the File MCBTSSubsystem. Continue this process, until you reach the end of the List.

In this way, all the respective filenames are transferred to the corresponding Files. Think that Regular Expressions might be required to implement the Logic of File Sorting.

Can anyone help me with a Perl Script for the same.

Thanks,

Kiran

Considered: gregor42 - reap: dupliate of Sorting names using Regular Expressions and placing them in different Files.. Final vote: Keep = 5, Edit = 1, Reap = 20.
Unconsidered: davido. Keep votes blocked reaping. Node has a followup, and is buried in a thread; reaping not advisable.

  • Comment on Re^7: Sorting names using Regular Expressions and placing them in different Files.

Replies are listed 'Best First'.
Re^8: Sorting names using Regular Expressions and placing them in different Files.
by strredwolf (Chaplain) on Dec 29, 2006 at 09:19 UTC
    Perl? Nah. BASH! First, since the format is XXXX-dddd, you can echo the filename to "cut" and use a shell escape to put the XXXX part into another shell variable. Then echo the filename into the file specified in that variable. Wrap a for loop for all files around it, and you got yourself a oneliner!

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";

Log In?
Username:
Password:

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