Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Matching string, then getting next line

by inman (Curate)
on Mar 08, 2006 at 11:35 UTC ( #535147=note: print w/replies, xml ) Need Help??


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

I guess that you are trying this with a file that has been generated on Windows and then transferred to a UNIX box. You end up with extra ^M chars when you look at the file using vi. Try trimming the surplus whitespace using a regex
#!/usr/bin/perl -w use strict; while (<MYFILE>){ s/\s+$//; if (/NEXT LINE MARKER/) { my $nextLine = <MYFILE>; $nextLine =~ s/\s+$//; print "$nextLine\n"; # do stuff with the next line here. } }

Replies are listed 'Best First'.
Re^4: Matching string, then getting next line
by minixman (Beadle) on Mar 08, 2006 at 11:53 UTC
    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:
      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://535147]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2016-10-01 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (9 votes). Check out past polls.