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.


In reply to Re^7: 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.