Try the following two files, an awk script and a sh script. Put them both in the same working directory.
- Put your text into lawdict.txt and ensure it conforms to the one requirement: that all of the ALL CAPS TITLES end with a comma (,).
- Execute the command
sh lawdict.sh.
- Edit lawdict.sql and change the last trailing comma to a semi-colon (;).
You now have an example of a shell-script-generated SQL command file.
It ain't perfect, and someone with a fresher brain will probably simplify this and make it about perfect. But the result (the example at the very end) is close to what you need.
lawdict.awk:
BEGIN { lineout = ""; printf("INSERT INTO law_dict_table VALUES\n");}
{
if ($0 ~ /^[A-Z ]*,/) {
if (substr(lineout, length(lineout)-6) == "</p><p>") {
lineout = substr(lineout, 1, length(lineout)-7);
}
printf("('%s'),\n", lineout);
lineout = $0;
} else {
if ($0 ~ /^$/) {
lineout = lineout "</p><p>";
} else {
lineout = lineout $0;
}
}
}
END {
printf("VALUES ('%s'),\n", lineout);
}
lawdict.sh:
#! /bin/sh
(
sed -e "s/'/\'/g" -e 's/\\/\\\\/g' lawdict.txt \
| awk -f lawdict.awk \
| sed -e 's= </p>=</p>=g' -e "s/^\(('[A-Z ]*\),/\1','/"
) > lawdict.sql
Example
lawdict.sql:
INSERT INTO law_dict_table VALUES
(''),
('A MENSA ET THORO',' from bed and board. A divorce a mensa et thoro, is rather a separation of the parties by act of law, than a dissolution of the marriage. It may be granted for the causes of extreme cruelty or desertion of the wife by the hushand. 2 Eccl. Rep. 208.</p><p>This kind of divorce does not affect the legitimacy of children, nor authorize a second marriage. V. A vinculo matrimonii; Cruelty Divorce.'),
('A PRENDRE',' French, to take, to seize, in contracts, as profits a prendre. Ham. N. P. 184; or a right to take something out of the soil. 5 Ad. & Ell. 764; 1 N. & P. 172 it differs from a right of way,</p><p>which is simply an easement or interest which confers no interest in the land. 5 B. & C. 221.'),
('A QUO',' A Latin phrases which signifies from which; example, in the computation of time, the day a quo is not to be counted, but the day ad quem is always included. 13 Toull. n. 52 ; 2 Duv. n. 22. A court a quo, the court from which an appeal has been taken; a judge a quo is a judge of a court below. 6 Mart. Lo. R. 520; 1 Har. Cond. L. R. 501. See Ad quem.'),
('A RENDRE',' French, to render, to yield, contracts. Profits a rendre; under this term are comprehended rents and services. Ham N. P. 192.'),
('A VINCULO MATRIMONII',' from the bond of marriage. A marriage may be dissolved a vinculo, in many states, as in Pennsylvania, on the ground of canonical disabilities before marriage, as that one of the parties was legally married to a person who was then living; impotence, (q. v.,) and the like adultery cruelty and malicious desertion for two years or more. In New York a sentence of imprisonment for life is also a ground for a divorce a vinculo. When the marriage is dissolved a vinculo, the parties may marry again but when the cause is adultery, the guilty party cannot marry his or her paramour.'),
VALUES ('AB INITIO, from the beginning.');