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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-11-2005
forevercalz forevercalz is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 74
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
  #2 (permalink)  
Old 12-12-2005
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 219
Have you thought about SQL Loader??
Invoking SQL Loader through a script can help you.
  #3 (permalink)  
Old 12-12-2005
forevercalz forevercalz is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 74
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..
  #4 (permalink)  
Old 12-12-2005
rahulrathod rahulrathod is offline
Registered User
  
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 158
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.
  #5 (permalink)  
Old 12-12-2005
rahulrathod rahulrathod is offline
Registered User
  
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 158
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.
  #6 (permalink)  
Old 12-12-2005
forevercalz forevercalz is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 74
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...
  #7 (permalink)  
Old 12-20-2005
a_akmal a_akmal is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 1
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
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 02:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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