![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
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
|
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
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.
|
|
#10
|
|||
|
|||
|
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 |
|
#11
|
|||
|
|||
|
Quote:
|
|
#12
|
|||
|
|||
|
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 |
|
#13
|
|||
|
|||
|
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 ?
|
|
#14
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |