Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you have one of these problems, and the file is not gigantic, one of the best tools for the job is perl in <a href="http://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlvar.pod#INPUT_RECORD_SEPARATOR" rel="nofollow"><code>undef $/</code></a> mode, which makes it read the entire file as one big string; this allows you to match <code>\n</code> just like any other character.</p> <p>At the character level, assuming there is no trailing horizontal whitespace on any line, a blank line is <em>two</em> newline characters in a row; two blank lines is three newline characters, and so on. To delete a blank line, you delete one of the two newline characters. Now, if you just write <code>s/\n\n/\n/g</code>, that will do more than you want, because <code>\n\n</code> will match pairs of newlines <em>within</em> longer runs of newlines. So you need a construct that will match two newlines in a row but <em>only if</em> they are not preceded or followed by more newlines. This is what <a href="http://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlre.pod#Look-Around_Assertions" rel="nofollow">look-around assertions</a> are for.</p> <pre><code>perl -pe 'BEGIN { undef $/ } s/\s+$//mg; s/(?&lt;!\n)\n\n(?!\n)/\n/sg' </code></pre> <p>should do the job. It will have the side effect of deleting trailing whitespace, if any, from every line of the file. If you want to delete double blank lines as well as single blank lines (but still not <em>triple</em> blank lines), you just have to adjust the middle of the second RE:</p> <pre><code>perl -pe 'BEGIN { undef $/ } s/\s+$//mg; s/(?&lt;!\n)\n{2,3}(?!\n)/\n/sg' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload