It may be useful to try something a little different.
Instead of querying from your input file, maybe change your shell program so that it reads each table name and writes an SQL query line into a file until you've run out of table names then execute the DBMS with that SQL file as input.
Where your file would look something like
select tabname, count from taba;
select tabname, count from tabb;
select tabname, count from tabc;
Now that's simplified, but pretty much that's what you'd want to do (and, you know, add whatever criteria you want to the select).
Then your shell program would
create an empty file (with > file.sql or similar)
open input text file
while read table name
append query into file.sql
close input text file
connect to DBMS and execute file.sql
Hope this helps some.