I have been unable to find this anywhere; I have a multiline variable, and I want to print the text between two patterns in that variable. So the variable is
My
real
name
is
not
Deadman
And I need the output to be this, by printing between "real" and "not"
name
is
or including the two patterns; doesn't matter.
The only ways I've seen of doing this don't involve searching a variable, only hardcoded __DATA__ or files
EDIT: by the way, sorry if I didn't make it clear, I want it all in perl, it's a perl script, not using other languages.
If I understand correctly, what that is doing is removing what you tell it to remove, am I right? If I am right, I can't use that, the damn file is 2149 lines, and it always changes.
If that's not what it's doing, can you show me how it would work with my example text?
but I do not play in PERL, being a sed or C or ksh guy. PERL may treat the string buffer as one line, or many, regardless of embedded characters. That is the 'like one line' solution, my first guess. Write a simple like the web site and try it out with a simple string that models your case, but simpler. The best knowledge is locally made.
Well, you are right that newlines are not considered . food in PERL like this. You could pull the lines one at a time, look for the first pattern, trim it, start printing and looking for the second pattern, when you find it, trim, print and stop, but that seems harder than should be necessary. Maybe there is a way to get the right substring in one fell swoop.
Else, you could shell out to sed, which is cheating.