in reply to Can't remember the term to search for help on!
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't remember the term to search for help on! (paragraph mode)
by tom2112 (Novice) on Dec 07, 2009 at 20:53 UTC | |
by tom2112 (Novice) on Dec 08, 2009 at 19:33 UTC |