The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix script to takes the old data from a TXT file and compress them into new file vpandey Shell Programming and Scripting 2 03-05-2008 11:10 AM
Need Shell Script to upload data from Text file to Oracle database chandrashekharj Shell Programming and Scripting 6 03-26-2007 03:21 AM
Shell Script for Data loading in Oracle raghuraja_r Shell Programming and Scripting 3 07-21-2006 10:00 AM
Shell Script to Load data into the database using a .csv file and .ctl file Csmani Shell Programming and Scripting 3 05-24-2006 08:09 AM
unix script to export data from csv file to oracle database vinayagan Shell Programming and Scripting 3 07-20-2005 04:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-24-2008
grajesh_955 grajesh_955 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 18
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 (permalink)  
Old 05-25-2008
FlyingSquirrel FlyingSquirrel is offline
Registered User
  
 

Join Date: May 2008
Posts: 38
Quote:
Originally Posted by grajesh_955 View Post
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 (permalink)  
Old 05-25-2008
grajesh_955 grajesh_955 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 18
Sorry...the actual ript has

cd $SCC
isql metdb >> ${LOGDATA}/LOAD.LOG << !
load from "${LDATA}/${FORM}.ld" insert into $LOADTABLE
!
  #4 (permalink)  
Old 05-25-2008
FlyingSquirrel FlyingSquirrel is offline
Registered User
  
 

Join Date: May 2008
Posts: 38
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 (permalink)  
Old 05-26-2008
grajesh_955 grajesh_955 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 18
yah.....Dude...I am using Informix database.....Plz gimme ur script for loading tables from pipe-delimited files.
  #6 (permalink)  
Old 11-08-2008
FlyingSquirrel FlyingSquirrel is offline
Registered User
  
 

Join Date: May 2008
Posts: 38
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0