texuser has asked for the wisdom of the Perl Monks concerning the following question:

I have a file which may include consecutive lines like this
\macroa xxxx (rest of line)
\macrob xxxx (rest of line)

I want to replace all such pairs with
\macroa xxxx (rest of line)
(blank line here)
\macrob xxxx (rest of line)

Is this possible with a perl one-liner?

Thank you.

  • Comment on Add blank line between two consecutive lines starting with specified strings

Replies are listed 'Best First'.
Re: Add black line between two consecutive lines starting with specified strings
by AnomalousMonk (Archbishop) on Feb 10, 2018 at 02:31 UTC

    It is certainly possible. Assuming Windows command line (update: and assuming "black" means "blank"), try (semi-tested):

    perl -wMstrict -pe "BEGIN { our $armed } $::armed = /\A \\macroa \s/x +? 1 : /\A \\macrob \s/x && $::armed && ! print qq{\n}" infile > outfi +le


    Give a man a fish:  <%-{-{-{-<

      Thank you, it works.

        I'm glad it works, and you're welcome. Do you understand why it works? We do not aspire to be a code-writing service. Evidence of effort on your part will beget effort on ours. Looking at your admittedly limited posting history ...


        Give a man a fish:  <%-{-{-{-<