Hi all,

I have one input file "pick no.txt" from which i have to find perticuler pattern and print it in to output file "Numbers.txt".

The input file is "pick no.txt"


Number:
Number-1999-1011
----------------------------------------
Number:
Number-1999-0696
----------------------------------------
Number:
Number-1999-0833,Number-2004-0786,Number-2004-0747,Number-2004-075,Number-2004-0748,Number-2004-0809
----------------------------------------
Number:
Number-2000-1209
----------------------------------------

The perl script i made for this is..
#!/usr/bin/perl open (RD, "pick no.txt") or die"Could not open file"; @Read = <RD>; close (RD); open (WR1, ">>Numbers.txt") or die"Could not open file"; for ($i=0; $i<= $#Read; $i++) { if($Read[$i] =~/^Number:/and $Read[$i+1]=~/(\w\w\w\w\w\w-\d\d\d\d-\d\ +d\d\d)/) { $Number = $1; $Number1 = substr ($Number, 7, 9); print "$Number1\n"; print WR1"$Number1\n"; } }


The output of the script is Numbers.txt..

1999-1011
1999-0696
1999-0833
2000-1209
The problem with this is it is not useful to search pattern occurance more than once in the same line. The numers after 1999-0833 is not shown in thw output.
Any suggestions for this?


--Mahesh

In reply to how to search a pattern occured more than once in line by mpatharkar

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.