Most tables which are scattered throughout the chapters are compiled into the appendix A, so they don't have to be rescanned here. Actually there is no table in the chapters, which is not found again in appendix A, but we cannot be sure here. What we do is just to scan for the headings of the tables, in order to merely catch the number of the table. Afterwards, we can check, if there is any more information to get, which we do not already have taken from appendix A.
For this kind of extraction we do not even need AWK. We let sed(1) run once over each chapter file with the following command, which appears as the only command in the `bin/chptbl' shell script.
sed -n -e "s/^TABLE \([0-9][0-9]*\).*/chapterTable(\1)./p" *.txt
This causes any line like the following example
TABLE 0002 MARITAL STATUS
to be output as
chapterTable(0002).
The latter is a Prolog predicate, which is then used to check for tables not yet known from appendix A.