in reply to Matching range of text with another string in between

perl -ne "BEGIN{ $/ = qq(\nCAS*\n) } /00003/ and print" "filename"

Since I don't have Windows, it is untested!

Replies are listed 'Best First'.
Re^2: Matching range of text with another string in between
by periodicalcoder (Novice) on Apr 22, 2016 at 17:17 UTC

    Anonymous, thank you for your contribution, but unfortunately your code returns the entire contents of the file. If you have any other thoughts please feel free to let us know.

      Does CAS* always start at the beginning of a line? And does the CAS* line have any trailing blanks?

        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.

      Try both of my one-liners on your little test data set from your original post. If one of them works, then your big data file is not what you think it is.

        It is the end of the day for me but I'll definitely take a look on Monday. I also may owe you all an apology as I left text out of my sample data, and I edited it so that it is now accurate. There is text that comes before the "00003" string, but I don't know how heavily that impacts the code that you gave me.

        I have made progress and I will post the updated code on Monday. I tend to like to sleep on things before asking for another round of help. I sincerely appreciate your help so far, and I apologize that it has been a bit frustrating.

      For Windows, try replacing \n with \r\n