unix script for loading a data from a file into database

Hi All,

I am trying to load a data from a files in a particular directory to a database..

cd $SCC
isql metdb >> ${LOGDATA}/LOAD.LOG < !
load from "${LDATA}/${FORM}.ld" insert into $LOADTABLE
!

But it's showing the error "syntax error at line 46 : `<<' unmatched"
Can u plz help me...

- - - -
It appears your here document needs one more less than sign

first part... <<!
commands...
!

Sorry...the actual ript has

cd $SCC
isql metdb >> ${LOGDATA}/LOAD.LOG << !
load from "${LDATA}/${FORM}.ld" insert into $LOADTABLE
!

What database are you using? (is it Informix?)

Take that space out between << and !

(not sure if that will help)
If it is informix I used to use a nice script for easily loading tables from pipe-delimited files.

yah.....Dude...I am using Informix database.....Plz gimme ur script for loading tables from pipe-delimited files.

This is a script I wrote that makes loading
pipe-delimited files very easy. You don't have to
create the command file because it does it for
you. It checks the first line of the file you are
loading to make sure that the number of fields and
the number of columns in the table match.
Syntax: dbload.sh databasename tablename
filename

Here it is:
###---cut here ---###
#!/bin/ksh
#Script: dbload.sh
# Freeware
#This utility runs the informix dbload utility
creating the required command
# file used by dbload automatically. It takes
three parameters,
# database, tablename, and pipe-delimited
datafile.
# It checks the 1st line of the datafile to make
sure that it contains
# the same number of fields as the table it is
being loaded into before
# a load can take place.
#Parameters:
# $1 = database name
# $2 = table name
# $3 = datafile name
# $4 = nocheck (optional, to avoid check on the
number of pipes in file and table)

USAGE="\n\nUsage: dbload.sh database tablename
datafile [nocheck]\n"
if (($# < 3)) #Three parameters
required
then
print "A utility to load a pipe-delimited
datafile into a database table"
print $USAGE
exit 1
fi

DATABASE=$1
TABLENAME=$2
DATAFILE=$3
NOCHECK=$4

#Return the # of columns in the database table
TBLCOLS=$(dbschema -d ${DATABASE} -t ${TABLENAME}
| grep "number of columns" | sed 's/^.columns =
//' | sed 's/ index.
$//')
if [[ -z $TBLCOLS ]]
then
print "Error: Table not found in database"
exit 1
fi
#echo "TABLE COLUMNS= " $TBLCOLS

if [[ $NOCHECK != "nocheck" ]]
then
#Return # of columns in datafile - must match
the table column count
#Sed passes 1st data row to sed remove all but
pipes and assign to string
PIPESTR=`sed -n '1,1p' ${DATAFILE} | sed
's/[^|]*//g'`
#The length of the string will be the number of
data columns in the file
DATCOLS=${#PIPESTR}
else
#No checking, assume the number of columns are
correct
DATCOLS=$TBLCOLS
fi

if [ $TBLCOLS = $DATCOLS ]
then
#echo "Table and datafile column counts are the
same"
print 'Processing ... Please Wait ...'
ERRSALLOWED=10
LOGFILE=load_${TABLENAME}.log

#build command file with unique timestamp
TIMESTAMP=`date +%y%m%d_%H%M%S`
CMDFILE=/tmp/loadcmd.$TIMESTAMP
echo "FILE "'"'${DATAFILE}'" DELIMITER "|"
'${TBLCOLS}';' > ${CMDFILE}
echo "INSERT INTO "${TABLENAME}';' >>
${CMDFILE}

dbload -d ${DATABASE} -c ${CMDFILE} -l
${LOGFILE} -e ${ERRSALLOWED}
rm ${CMDFILE}
print "Loading Completed."
else
echo "Table and Datafile Number of Columns do
not match: " ${TBLCOLS} " and " ${DATCOLS}
fi

###--- cut here ---###

What you could do is have a script that does the
something like following:

echo 'drop table mytable' | dbaccess mydatabase
dbaccess mydatabase mycreatetablescript.sql
dbload.sh mydatabase mytable mydatafile

I hope that helps.