Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found