Debian Codegraph @

paragraph-space.sh

raw symbols SCIP
1 #!/bin/bash
2 # paragraph-space.sh
3 # Ver. 2.1, Reldate 29Jul12 [fixup]
4
5 # Inserts a blank line between paragraphs of a single-spaced text file.
6 # Usage: $0 <FILENAME
7
8 MINLEN=60 # Change this value? It's a judgment call.
9 # Assume lines shorter than $MINLEN characters ending in a period
10 #+ terminate a paragraph. See exercises below.
11
12 while read line # For as many lines as the input file has ...
13 do
14 echo "$line" # Output the line itself.
15
16 len=${#line}
17 if [[ "$len" -lt "$MINLEN" && "$line" =~ [*{\.}]$ ]]
18 # if [[ "$len" -lt "$MINLEN" && "$line" =~ \[*\.\] ]]
19 # An update to Bash broke the previous version of this script. Ouch!
20 # Thank you, Halim Srama, for pointing this out and suggesting a fix.
21 then echo # Add a blank line immediately
22 fi #+ after a short line terminated by a period.
23 done
24
25 exit
26
27 # Exercises:
28 # ---------
29 # 1) The script usually inserts a blank line at the end
30 #+ of the target file. Fix this.
31 # 2) Line 17 only considers periods as sentence terminators.
32 # Modify this to include other common end-of-sentence characters,
33 #+ such as ?, !, and ".