Hi monks, i have a file whose contents are as below:
<first line> :ctx ctx_3 ctx_3 040425 0 0 +07-May-2004 03:29 07-May-2004 03:29 0.00 hobbit + N/A failed PLE-QA N/A 0 <second line> Not Published 466008691 <third line>plsql tkmain_ps4 tkmain_ps4 040425 0 + 0 07-May-2004 03:29 07-May-2004 03:29 0.00 + hobbit N/A failed PLE-QA N/A 0 <...> Not Published 466008691 <nth line>plsql tkmain_pu3 tkmain_pu3 040425 0 + 0 07-May-2004 03:29 07-May-2004 03:29 0.00 h +obbit N/A failed PLE-QA N/A 0 Not Published 466008691 rdbms tkmain_2n1 tkmain_2n1 040425 0 0 + 07-May-2004 01:37 07-May-2004 01:37 0.00 hobbit + N/A failed PLE-QA N/A 0 Not Published 465894765
I want only the first two words(for ex:ctx ctx_53) from each of the lines that begin with the similar kind of words like the third line has - plsql tkmain_ps4 and i want this to be matched. I have written the following but isnt working...could any of you please help...i am a begginner at perl.
#! /usr/local/bin/perl #use strict; open(rerun,"rerunlrg") while(my $pattern=<rerun>){ if(my $pattern=~ m/^(\w\s+\w\s).*?/){ print "matched\n"; print "$1\n"; }
Thanks ppl

Edited by Chady -- added code tags around file contents.


In reply to first two words-pattern matching by shamala

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.