The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do i check whether a file has extension? sunday8 Shell Programming and Scripting 2 08-29-2008 06:58 PM
how to unzip File which has no extension thepurple SUN Solaris 13 11-29-2007 02:46 AM
Stripping out the extension of a file name ramky79 Shell Programming and Scripting 2 12-27-2006 11:25 AM
Check file extension mahalakshmi Shell Programming and Scripting 6 12-27-2006 10:15 AM
default extension of file rujupriya UNIX for Dummies Questions & Answers 2 05-17-2006 07:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 01-14-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
lets go through a step at a time. remove your mysql command
Code:
#!/bin/ksh
DIR="/root/test/statbackup"
if [ -d "$DIR" ]; then
        cd $DIR
else
        print "ERROR: Directory doest not exist!"
fi
for file in * ; do
        case $file in
                *.88)
                cat <<EOFMYSQL
LOAD DATA LOCAL INFILE '$DIR/$file' INTO TABLE Test1 FIELDS TERMINATED BY '|'
IGNORE 1 LINES;
EOFMYSQL
                ;;
                *.99)
                cat <<EOFMYSQL
LOAD DATA LOCAL INFILE '$DIR/$file' INTO TABLE Test2 FIELDS TERMINATED BY '|'
IGNORE 1 LINES;
EOFMYSQL
                ;;
                *)
                print "Usage: $file is not in correct format"
                ;;
        esac
done
the above works on my system. Once you get it working, substitute back your mysql commands. if you hit problem again, you can at least know where to look
Reply With Quote
Forum Sponsor
  #9  
Old 01-14-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 570
Replace the starting "EOFMYSQL" here document delimiter with "-EOFMYSQL". The dash character before the EOFMYSQL will strip all leading blanks or tabs and the mysql binary won't terminate with "unexpected end of file" error.
Reply With Quote
  #10  
Old 01-14-2008
Registered User
 

Join Date: Oct 2007
Posts: 19
Thank you

Hi all,

The script is working now with "-EOFMYSQL". Thank you all of you for your guidance and assistant.

Between, I have one question here that want to check with all of you. Is there any command in shell script that can be use to convert date format from "STRING to DATE"? Please advise.

Thank you so much.

Br,
Shirley
Reply With Quote
  #11  
Old 01-14-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by shirleyeow View Post
Hi all,

The script is working now with "-EOFMYSQL". Thank you all of you for your guidance and assistant.

Between, I have one question here that want to check with all of you. Is there any command in shell script that can be use to convert date format from "STRING to DATE"? Please advise.

Thank you so much.

Br,
Shirley
show some examples?
Reply With Quote
  #12  
Old 01-15-2008
Registered User
 

Join Date: Oct 2007
Posts: 19
Date datatype conversion

Hi ghostdog74,

Here the sample of the text file:

Date|NumberofCustomer
010108| 200
020108| 450
030108| 600

When I load this text file into database, if I declare the Date column as "DATE" datatype, after loaded the text file, the value in Date column become 00:00:00. If I declare the Date column as "VARCHAR", then the value in the text file is loaded correctly into the database.

I plan to convert the Date datatype first by shell script before load the text file into database. But I cant find any command for doing this. Just wondering whether shell script have this kind of datatype conversion command or not.

Please advise.

Thank you.

Br,
Shirley
Reply With Quote
  #13  
Old 01-15-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by shirleyeow View Post
010108| 200
020108| 450
030108| 600

When I load this text file into database, if I declare the Date column as "DATE" datatype, after loaded the text file, the value in Date column become 00:00:00.
do u mean that the values 010108, 020108 and 030108 all become 00:00:00 in your table's first column ? I do not have mysql to experiment, however you can try declaring as DATETIME ?
Reply With Quote
  #14  
Old 01-15-2008
Registered User
 

Join Date: Oct 2007
Posts: 19
Date datatype conversion

Hi ghostdog74,

Yup, all the date value 010108, 020108, 030108 become 00:00:00 after load the text file into database if I declare the Date column as "DATE or DATETIME" datatype. But if I declare the date column as "VARCHAR", then the value can be insert into the Date column correctly.

I just worry if I declare the Date column as "VARCHAR", may be later will cause some problem to the database.

So just want to find some way to convert the date format first before load it into database. Any suggestion?

Thank you.

Best Regards,
Shirley
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0