good chemistry is complicated,
and a little bit messy -LW
matching first paragraph satisfying conditionby mnshptl32 (Initiate)
|on Aug 05, 2019 at 16:14 UTC||Need Help??|
mnshptl32 has asked for the wisdom of the Perl Monks concerning the following question:
Greetings! I just registered here and hope this is an appropriate venue for my question.
I'm new to perl and am trying to write a perl one-liner that returns everything from the first non-indented line of a file up until the end of that paragraph, terminated by a blank line. I can do this using awk with the command:
My problem translating this to perl is that the first non-indented line of the file may or may not be the first line of the file. In the former case, this works:
as does this:
In the latter case, this works:
But is there a simple perl one-liner that works in both cases? I've tried writing a semicolon-separated perl command intended to prepend a blank line to the file before the search in the event that the first line is not indented, using something like
but I can't get the syntax right. Obviously I could string together a sequence of commands like
or use some bash conditional like
however, I'd like to know if there's some more elegant "pure perl" solution I'm overlooking.