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 to insert data into MYSql database from a text file shirleyeow Shell Programming and Scripting 4 01-11-2008 01:00 AM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-09-2007 11:25 PM
Need Shell Script to upload data from Text file to Oracle database chandrashekharj Shell Programming and Scripting 6 03-26-2007 12:21 AM
insert text into top of file jimbob Shell Programming and Scripting 1 09-22-2006 02:46 PM
SED- Insert text at top of file MBGPS Shell Programming and Scripting 12 07-03-2002 06:48 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
Stumble this Post!
how to insert data in database based on text file?

Hi....can you guys help me out in this script??

Below is a text file script....called Bukom.txt and it contains these:

BUKOM 20060101 2.5 2.6 2.7 2.8 2.9 2.3 2.1
BUKOM 20060102 2.4 2.5 2.6 2.7 2.7 2.6 2.4
BUKOM 20060103 2.1 2.3 2.5 2.6 2.7 2.7 2.6

I would like this set of data to be auto read by the script to be insert into the database.
The database table is call bukom_table
and its contains 4 fields..namely:
locn,
date,
hour,
strength..

How to create a script that insert this data into the database?
for example bukom will be in locn...and i do not want anyspace behind.
and for the date will be 20060101 and the strength will be 2.5.

ok for the fields hour it will have to create manually...like for first row..2.5 is the strength and 0000 will be hour..follow by 2.6 will be 0030 hour and 2.7 will be 0100 hour. likewise for the second row...2.4 will be 0000 hour and 2.5 will be 0030 hour and so on...

im having a headache now on working on this scripts....hope you(expertists) can help a million thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-12-2005
encrypted's Avatar
Registered User
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 218
Stumble this Post!
Have you thought about SQL Loader??
Invoking SQL Loader through a script can help you.
Reply With Quote
  #3 (permalink)  
Old 12-12-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
Stumble this Post!
yes...i thought of that too.... however my text file is not formated in a way to be append in and its a very huge set of data..
Reply With Quote
  #4 (permalink)  
Old 12-12-2005
Registered User
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 151
Stumble this Post!
Make a new formatted file

You can write code to create the formmated data you want and write it to a csv file. The format of the csv files should be:

field1,field2,field3,field4

You should then need a corresponding ctl file containg the column names in a comma separated format. Then you can have a shell script calling the sqlldr which can use the data and ctl files.

Regards,
Rahul.
Reply With Quote
  #5 (permalink)  
Old 12-12-2005
Registered User
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 151
Stumble this Post!
And however large the mount of data maybe there are many options in sqlldr to load it into the DB in less than a minute. Just take care that the table u r inserting data into does not have any indexes created on them.
Reply With Quote
  #6 (permalink)  
Old 12-12-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
Stumble this Post!
i got over thousands of data and its hard for me to format all into the correct fields....i need a script to auto read it as there are more than 8 files to read from.......above are my problems....as you see the hour field needed to be inserted manually..i will need days to insert it as the records are too much...
Reply With Quote
  #7 (permalink)  
Old 12-19-2005
Registered User
 

Join Date: Dec 2005
Posts: 1
Stumble this Post!
You can with mysqlimport

Quote:
Originally Posted by forevercalz
Hi....can you guys help me out in this script??

Below is a text file script....called Bukom.txt and it contains these:

BUKOM 20060101 2.5 2.6 2.7 2.8 2.9 2.3 2.1
BUKOM 20060102 2.4 2.5 2.6 2.7 2.7 2.6 2.4
BUKOM 20060103 2.1 2.3 2.5 2.6 2.7 2.7 2.6

I would like this set of data to be auto read by the script to be insert into the database.
The database table is call bukom_table
and its contains 4 fields..namely:
locn,
date,
hour,
strength..

How to create a script that insert this data into the database?
for example bukom will be in locn...and i do not want anyspace behind.
and for the date will be 20060101 and the strength will be 2.5.

ok for the fields hour it will have to create manually...like for first row..2.5 is the strength and 0000 will be hour..follow by 2.6 will be 0030 hour and 2.7 will be 0100 hour. likewise for the second row...2.4 will be 0000 hour and 2.5 will be 0030 hour and so on...

im having a headache now on working on this scripts....hope you(expertists) can help a million thanks




mysqlimport --fields-terminated-by=" " your_database Bukom.txt
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0