Finding tables from each script

Hi,

I just want to take each sql script from specified directory and print all tables in those sqls. Below is the script but getting an error lik

ksh: 0403-057 Syntax error: `(' is not expected.

Script is----

ls /ukdw/prd/working/TDMatrix/srualcb02/ukdw/prd/bin | awk '{printf("%s ",$0)}END{print "\n"}'
for(sc=1;sc<=NF;sc++)
{
grep -iE "ABC|DEF" /ukdw/prd/working/TDMatrix/srualcb02/ukdw/prd/bin/$sc | awk '{printf("%s ",$0)}END{print "\n"}' | sed 's/,/ /g;s/ / /g' |
awk 'BEGIN{FS=" "}
{
for(i=1;i<=NF;i++)
{
fieldToCheck=toupper($i);
if (index(fieldToCheck,"ABC")>0){print $i};
if (index(fieldToCheck,"DEF")>0){print $i}
}
}'
}

PLZ suggest

The for loop is not in shell syntax. It looks like a piece of awk script.

From your problem description, I would guess you mean something like

for sc in /ukdw/prd/working/TDMatrix/srualcb02/ukdw/prd/bin/*; do
    grep -iwoE "ABC|DEF" "$sc"
done

which of course can be further simplified to

grep -iwohE "ABC|DEF" /ukdw/prd/working/TDMatrix/srualcb02/ukdw/prd/bin/*

I'm wildly speculating about what you want the inner loop to do here, but your problem description sounds like the above would be closer to what you really want than what you have now. Perhaps you can explain in more detail what input file looks like, and what you want to extract from it.

Thanks for the replay.

My outer loop is just taking one file at a time from the specified directory.
My second loop is taking that file and doing some search operation based on some criteria.

I tested the second loop alone and it is working fine. Just having problem to put an outer loop which ll give one by one file name to the second loop.

Hope i am making sence.