Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: Matching string, then getting next line

by minixman (Beadle)
on Mar 08, 2006 at 11:53 UTC ( #535151=note: print w/replies, xml ) Need Help??


in reply to Re^3: Matching string, then getting next line
in thread Matching string, then getting next line

That does work, but it splits out the lines that i am looking for so when i run it i end up with.
#!/usr/bin/perl open(MYFILE, "log.log"); while (<MYFILE>){ s/\s+$//; if (/Message\sdump:/) { my $nextLine = <MYFILE>; $nextLine =~ s/\s+$//; print "Found=$nextLine\n"; # do stuff with the next line here. } }

Found=23 06/02/23 11:19:34:750 Received FIX message Found=8=FIX.4.29=024935=D34=743=N49=COMPLEX_EXLINK50=DBL9991456=EXLINK +_COMPLEX57=COMPLEXGATE97=N52=20060223-11:18:4660=20060223-11:18:46207 +=XEUR55=XEURFDAX0F2006H200=20060340=259=044=58681=L60954=111=Order58: +1:1140693526109=DBL9991421=238=1167=FUT10=096
When the format is
Message dump: 8=TEST.4.29=038435=849=TEST56=TEST50=COMPLEXGATE57=DBL9991134=852=2006 +0223-11:19:351=L6096=0.000011=Order58:1:114069352614=0.000017=11193 54210120=031=0.0000000032=0.000037=132710015138=1.000039=854=155=XEURF +DAX0F2006H58=EUREX Error PRICE60=20060223-11:19:34150=8151=1.0000109= +D BL9991463=0167=TEST=200603207=TEST=244=5868.0000000010=101 25 06/02/23 11:20:00:765 Received TEST message Message dump: 8=TEST.4.29=025135=D34=843=N49=TEST50=TEST=TEST57=COMPLEXGATE97=N52=20 +060223-11:19:1060=20060223-11:19:10207=XEUR55=XEURFDAX0F2006H 200=20060340=259=044=5867.51=L60954=111=Order63:1:1140693551109=DBL999 +1421=238=1167=FUT10=166 26 06/02/23 11:20:01:500 Sent TEST Message Message dump:

Replies are listed 'Best First'.
Re^5: Matching string, then getting next line
by wazoox (Prior) on Mar 08, 2006 at 13:05 UTC
    Actually you'd better remove only the ending "CR" characters, not spaces :
    while (<MYFILE>) { s/\r\n$/\n/g; ... }
    This simply replace "<CR><LF>" (DOS end of lines) with "<LF>" (Unix end of line)
      Maybe a better option would be to try and split out everything between the message dump: and message dump: Is there a way to say something like
      if($_ =~ /Message Dump:(.*) Message Dump:/)
      And then the whole string would be in something like $1
        You can try to change the line separator $/ to "Message Dump:", then each line would end with "Message Dump:". However the conversion from DOS to Unix line ends is more standard and reusable...
        my @messages; my $inmessage = 0; # 0 false, 1 true while ( <FILE> ) { s/\r\n$/\n/ ; if ( $inmessage) { push $_, @messages; } if ( m/Message Dump:.*/ ) { # we set $inmessage to 1 if 0, or 0 if 1 $inmessage = abs( $inmessage -1 ) ; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://535151]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2018-07-16 18:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (346 votes). Check out past polls.

    Notices?