Need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help
# 15  
Old 01-26-2007
#!/usr/bin/ksh

COUNT=1
nawk '{ print $1 }' tables.* | \
while read TABLE
do
echo "delete from ${TABLE}"
echo ".IF ERRORCODE <> 0 Then .QUIT ${COUNT}"
((COUNT=${COUNT}+1))
done > <file>
# 16  
Old 01-26-2007
script:

#!/usr/bin/ksh

INPUTFILE=${1}
COUNT=1
nawk '{ print $1 }' ${INPUTFILE} | \
while read TABLE
do
echo "delete from ${TABLE}"
echo ".IF ERRORCODE <> 0 Then .QUIT ${COUNT}"
((COUNT=${COUNT}+1))
done > ${INPUTFILE}.out

Execute:

e.g.
./script tables.1
./script tables.2
# 17  
Old 01-26-2007
if you have Python, here's an alternative:
Code:
import glob
quit=1
o=open("deletescript","a") #output file handle
#assume all your files in one directory and ext = .txt
for files in glob.glob("*.txt"):
        for line in open(files):
                tablename = line.split()[0]
                o.write("delete from %s;\n" % tablename)
                o.write(".IF ERRORCODE <> 0 Then .QUIT %d\n"%quit)
                quit+=1
o.close() #close file handle

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question