Debian Codegraph @

find-splitpara.sh

raw symbols SCIP
1 #!/bin/bash
2 # find-splitpara.sh
3 # Finds split paragraphs in a text file,
4 #+ and tags the line numbers.
5
6
7 ARGCOUNT=1 # Expect one arg.
8 OFF=0 # Flag states.
9 ON=1
10 E_WRONGARGS=85
11
12 file="$1" # Target filename.
13 lineno=1 # Line number. Start at 1.
14 Flag=$OFF # Blank line flag.
15
16 if [ $# -ne "$ARGCOUNT" ]
17 then
18 echo "Usage: `basename $0` FILENAME"
19 exit $E_WRONGARGS
20 fi
21
22 file_read () # Scan file for pattern, then print line.
23 {
24 while read line
25 do
26
27 if [[ "$line" =~ ^[a-z] && $Flag -eq $ON ]]
28 then # Line begins with lowercase character, following blank line.
29 echo -n "$lineno:: "
30 echo "$line"
31 fi
32
33
34 if [[ "$line" =~ ^$ ]]
35 then # If blank line,
36 Flag=$ON #+ set flag.
37 else
38 Flag=$OFF
39 fi
40
41 ((lineno++))
42
43 done
44 } < $file # Redirect file into function's stdin.
45
46 file_read
47
48
49 exit $?
50
51
52 # ----------------------------------------------------------------
53 This is line one of an example paragraph, bla, bla, bla.
54 This is line two, and line three should follow on next line, but
55
56 there is a blank line separating the two parts of the paragraph.
57 # ----------------------------------------------------------------
58
59 Running this script on a file containing the above paragraph
60 yields:
61
62 4:: there is a blank line separating the two parts of the paragraph.
63
64
65 There will be additional output for all the other split paragraphs
66 in the target file.