in reply to Re^3: Matching range of text with another string in between
in thread Matching range of text with another string in between

I tried changing \n to \r\n as follows, but it still returned the entire contents:
perl -ne "BEGIN{ $/ = qq(\r\nCAS*\r\n) } /00003/ and print" "filename"
Yes, CAS* always starts at the beginning of the line, and those lines do not have any trailing blanks. I want to make sure that the matching entries start with LX* and end with CAS*. I could be wrong but it almost looks like the code above is matching starting with CAS* instead.

Replies are listed 'Best First'.
Re^5: Matching range of text with another string in between
by Anonymous Monk on Apr 22, 2016 at 18:41 UTC

    $/ is endofline (see perldoc perlvar). At this point I no longer trust your data file and would use a dump program to verify that the sequence \r\nCAS*\r\n exists in the file.

Re^5: Matching range of text with another string in between
by Anonymous Monk on Apr 22, 2016 at 18:46 UTC

    Are you sure it is not a Mac file? They have different line endings.

      It looks like I misunderstood your question about the line endings. The file is provided by MediCal and is in the "ANSI ASC X12" format which they also referred to as an "ANSI 835s" file.

      According to Notepadd++ the end of line characters are CR LF. I hope that helps.

        Editors often mess with line endings, and are not to be trusted. Does Windows have a raw dump program (like Linux "od") that can show real file contents?

        I looked up a spec for 835 and there is no CAS* There are CAS01 through CAS19 Was your test case real? Are there really *'s in the file?