| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
ARGCOUNT=1 |
| 8 |
OFF=0 |
| 9 |
ON=1 |
| 10 |
E_WRONGARGS=85 |
| 11 |
|
| 12 |
file="$1" |
| 13 |
lineno=1 |
| 14 |
Flag=$OFF |
| 15 |
|
| 16 |
if [ $# -ne "$ARGCOUNT" ] |
| 17 |
then |
| 18 |
echo "Usage: `basename $0` FILENAME" |
| 19 |
exit $E_WRONGARGS |
| 20 |
fi |
| 21 |
|
| 22 |
file_read () |
| 23 |
{ |
| 24 |
while read line |
| 25 |
do |
| 26 |
|
| 27 |
if [[ "$line" =~ ^[a-z] && $Flag -eq $ON ]] |
| 28 |
then |
| 29 |
echo -n "$lineno:: " |
| 30 |
echo "$line" |
| 31 |
fi |
| 32 |
|
| 33 |
|
| 34 |
if [[ "$line" =~ ^$ ]] |
| 35 |
then |
| 36 |
Flag=$ON |
| 37 |
else |
| 38 |
Flag=$OFF |
| 39 |
fi |
| 40 |
|
| 41 |
((lineno++)) |
| 42 |
|
| 43 |
done |
| 44 |
} < $file |
| 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. |