unix script for loading a data from a file into database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unix script for loading a data from a file into database
# 1  
Old 05-25-2008
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...
# 2  
Old 05-25-2008
Quote:
Originally Posted by grajesh_955
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...
!
# 3  
Old 05-25-2008
Sorry...the actual ript has

cd $SCC
isql metdb >> ${LOGDATA}/LOAD.LOG << !
load from "${LDATA}/${FORM}.ld" insert into $LOADTABLE
!
# 4  
Old 05-25-2008
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.
# 5  
Old 05-26-2008
yah.....Dude...I am using Informix database.....Plz gimme ur script for loading tables from pipe-delimited files.
# 6  
Old 11-08-2008
Load pipe-delimited files using Informix

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to avoid locks while loading database through UNIX script.?

Hi, I have the following requirement: I have load_cdr as main scriptwhich loads all the file records into vertica database through unix script. But there are two files which try to update same table..n thats y my script is getting failed... Can any1 give me some logic how to over come this... (6 Replies)
Discussion started by: gnnsprapa
6 Replies

2. Shell Programming and Scripting

why do we need UNIX shell script to load data into Oracle database

Hello everyone, I am new to shell scripting/ loading data into a database. I want to load data into Oracle database using SQL loader. Can some one please explain why do we need unix shell script to load the data into the database? Also can someone please explain what has to be in that script?... (5 Replies)
Discussion started by: new_prog
5 Replies

3. UNIX for Advanced & Expert Users

creating data loading script

asdfasdfasdfasdf??? (2 Replies)
Discussion started by: noorm
2 Replies

4. Shell Programming and Scripting

Help with loading data from DB2 database to CSV file

Hi everyone!! I need help regarding this. How can we load data from DB2 Database tables into a Comma Separated File? I also have another Question? Using Shell scripting, Is it easy to read Data from a table or from a text file? It is very urgent for me. Please help me out guys. ... (1 Reply)
Discussion started by: ss3944
1 Replies

5. UNIX for Dummies Questions & Answers

data is seen as NULL after loading into database

hello, when I load a data from text file all the values become NULL in the table. Please help me with this problem. Thanks sheen (15 Replies)
Discussion started by: sheen
15 Replies

6. Shell Programming and Scripting

Loading Oracle data to unix in flat file

Hi I would like to know how to load oracle data to unix flat file using a shell script. Can we use sqlldr to import data from oracle, if so can anyone help me with it. (2 Replies)
Discussion started by: raghav288
2 Replies

7. Shell Programming and Scripting

Need Shell Script to upload data from Text file to Oracle database

Hi Does any one have any idea on uploading the data using Unix Shell script from text file to Oracle database. Requirement:- 1. Need to connect to Oracle database from Unix Shell script. 2. Need to pick Text file from some location on Unix Box. 3. Need to upload the data from text file to... (6 Replies)
Discussion started by: chandrashekharj
6 Replies

8. Shell Programming and Scripting

Shell Script for Data loading in Oracle

Hi All I am new to unix. I need a shell script to load a datafile in to oracle. I already have a control file, and data file. all I need is if i execute the shell it must load the data using the ctl file to table. Control file : PAY0001.ctl Datafile : mon_grs_det.dat log file :... (3 Replies)
Discussion started by: raghuraja_r
3 Replies

9. Shell Programming and Scripting

Shell Script to Load data into the database using a .csv file and .ctl file

Since i'm new to scripting i'm findind it difficult to code a script. The script has to be an executable with 2 paramters passed to it.The Parameters are 1. The Control file name(.ctl file) 2. The Data file name(.csv file) Does anybody have an idea about it? :confused: (3 Replies)
Discussion started by: Csmani
3 Replies

10. Shell Programming and Scripting

unix script to export data from csv file to oracle database

Hello people, Need favour. The problem I have is that, I need to develop a unix shell script that performs recurring exports of data from a csv file to an oracle database. Basically, the csv file contains just the first name and last name will be dumped to an Unix server. The data from these... (3 Replies)
Discussion started by: vinayagan
3 Replies
Login or Register to Ask a Question