Help with Pattern matching. Matching multiple lines from while reading from a file.

Discussion in 'Perl Misc' started by Bobby Chamness, May 3, 2007.

  1. Example from a file I'm reading.

    2007-04-17 09:35:34 ACSSA[0]:
    1431 N sa_demux.c 1 276
    drive 4, 1, 1,11: Library error, Transport failure

    I want to match the first and third line, that way I know the date and
    drive info.

    so the output on the print will look like this
    2007-04-17 09:35:34 ACSSA[0]: drive 4, 1, 1,11: Library error, Transport
    failure
    Bobby Chamness, May 3, 2007
    #1
    1. Advertising

  2. On Wed, 2 May 2007 22:37:33 -0500, "Bobby Chamness"
    <> wrote:

    >Example from a file I'm reading.
    >
    >2007-04-17 09:35:34 ACSSA[0]:
    >1431 N sa_demux.c 1 276
    >drive 4, 1, 1,11: Library error, Transport failure


    All entries like this one? Separated by blank lines? Not separated?

    >I want to match the first and third line, that way I know the date and
    >drive info.


    Depending on the answer to the questions above and the size of the
    file, either slurp the file in and match over multiple lines or read
    line by line and if match occurs read some more lines or if the
    "format" is reliable enough do not match at all

    >so the output on the print will look like this
    >2007-04-17 09:35:34 ACSSA[0]: drive 4, 1, 1,11: Library error, Transport
    >failure


    I'm still failing to see what you've tried thus far and how it doesn't
    work for you. Under optimistic assumptions even the following oneliner
    may work for you:

    perl -lpe '<>;$_.=" ".<>'


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, May 3, 2007
    #2
    1. Advertising

  3. Bobby Chamness

    Xicheng Jia Guest

    On May 2, 11:37 pm, "Bobby Chamness" <> wrote:
    > Example from a file I'm reading.
    >
    > 2007-04-17 09:35:34 ACSSA[0]:
    > 1431 N sa_demux.c 1 276
    > drive 4, 1, 1,11: Library error, Transport failure
    >
    > I want to match the first and third line, that way I know the date and
    > drive info.
    >
    > so the output on the print will look like this
    > 2007-04-17 09:35:34 ACSSA[0]: drive 4, 1, 1,11: Library error, Transport
    > failure


    If all independent records are seperated by empty line, and you want
    to remove the second line of all the three-line records, then

    perl -00pe 's/\n.*\n/ /' file.txt

    Regards,
    Xicheng
    Xicheng Jia, May 3, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Wright
    Replies:
    0
    Views:
    496
    Joe Wright
    Jul 27, 2003
  2. Sukhwinder Tambar

    Reading RTF + Text File and pattern matching

    Sukhwinder Tambar, Jan 12, 2009, in forum: Ruby
    Replies:
    2
    Views:
    143
    Sukhwinder Tambar
    Jan 15, 2009
  3. Jamie Jackson

    Spanning Lines & Dynamic Pattern Matching

    Jamie Jackson, Oct 25, 2004, in forum: Javascript
    Replies:
    5
    Views:
    93
    Jamie Jackson
    Oct 26, 2004
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    220
    Marc Bissonnette
    Jan 13, 2004
  5. Cah Sableng
    Replies:
    0
    Views:
    230
    Cah Sableng
    Apr 23, 2007
Loading...

Share This Page