summaryrefslogtreecommitdiffstats
path: root/.local/bin/sentences
blob: 750072ebea55600e742b554d88929279fcd33a79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl

use strict;

my $pont = qr{[.!?]+};                            ## punctuation
my $abrev = qr{\b(?:Pr|Dr|Mr|[A-Z]|i\.e|e\.g|et al|etc|p|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|vs)\.}; ## abbreviations
my $header = qr{(=+ .*? =+)};

$/ = "";

while(<>) {
    chomp;                     ## for each paragraph,

    s/\h*\n\h*/ /g;            ## remove \n
    s/($pont)\h+(\S)/$1\n$2/g; ## punctuation+space
    s/($abrev)\n/$1 /g;        ## undo \n after abbreviations
    s/$header\h+(\S)/$1\n$2/g; ## vimwiki headers

    print "$_\n";
}