See perlrun, there "paragraph mode". The boundary between paragraphs in that mode may comprise several blank lines.

Given a file named "text" as follows

this is the first paragraph. It has three lines. Of which this one is the third. A blank line denotes a paragraph. This one has got two lines only. The third paragraph is preceded with several blank lines, and it has itself three, no, wait, four lines. Last paragraph. All paragraphs should be shown each as one line running "perl -p00 -le 's/\n/ /gs;s/\s+/ /g;'" on that file, with multiple blanks condensed into one.

the snippet

perl -p00 -le 's/\n/ /gs;s/\s+/ /g;' text

does what you want. If you want inplace-edit (see perlrun again), say

perl -p00 -i.bak -le 's/\n/ /gs;s/\s+/ /g;' text

to have the file backed up with the suffix .bak as text.bak

You can provide multiple files on the command line; each will be processed in turn (and backed up, if requested).


In reply to Re: Can't remember the term to search for help on! (paragraph mode) by shmem
in thread Can't remember the term to search for help on! by tom2112

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.