![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 04:21 AM |
| Shell Script for Data loading in Oracle | raghuraja_r | Shell Programming and Scripting | 3 | 07-21-2006 11: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 09:09 AM |
| unix script to export data from csv file to oracle database | vinayagan | Shell Programming and Scripting | 3 | 07-20-2005 05:16 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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... |
|
||||
|
Quote:
It appears your here document needs one more less than sign first part... <<! commands... ! |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|