how to insert data into database by reading it from a text file??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to insert data into database by reading it from a text file??
# 1  
Old 10-30-2008
how to insert data into database by reading it from a text file??

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

Below is a text file and it contains these:

GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001
GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001
GEF001 000093625 MKL005675 000001 000000 000000 000000 000000 000000 000001
GEF001 000093625 MKL005678 000001 000000 000000 000000 000000 000000 000001
I would like the first 3 columns of data to be read by the script to insert into the database.
The database table is IMSERNOS
and its contains 3 fields..namely:
ImiCode varchar2(6),
CustNo varchar2(9),
SerNo varchar2(9)


How to create a script that reads the data and insert this data into the database?

im having a headache now on working on this scripts....hope you(expertists) can help Smilie a million thanks Smilie
# 2  
Old 10-30-2008
what have you got so far, what do you use to process the SQL statements?
# 3  
Old 10-30-2008
am not getting how to start with this... am searching for answers in google and getting confused wit everything
# 4  
Old 10-30-2008
Code:
#!/bin/bash

function processline
{
    ImiCode=$1
    CustNo=$2
    SerNo=$3
    SQL="insert into IMSERNOS (ImiCode,CustNo,SerNo) values ('$ImiCode','$CustNo','$SerNo')"
    echo $SQL
}

while read line
do
    processline $line
done

call the above like
Code:
<text.file |processfile >sql.output

which should give you nicely formatted sql statements for further processing

Last edited by wempy; 10-30-2008 at 08:52 AM.. Reason: added instructions
# 5  
Old 10-30-2008
thank you so much for the quick reply....
i wil start wit this script....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

2. Programming

Need help on Insert data to mySQL database

Hi guys, I would like to seek help on inserting data whenever the switch is on or off to my sensor mySQL database in phpMyAdmin from my control.php. I'm using Raspberry PI as my hardware and follow a few tutorials to create my own Web Control Interface, it works perfectly without insert method.... (1 Reply)
Discussion started by: aoiregion
1 Replies

3. Shell Programming and Scripting

Korn shell program to parse CSV text file and insert values into Oracle database

Enclosed is comma separated text file. I need to write a korn shell program that will parse the text file and insert the values into Oracle database. I need to write the korn shell program on Red Hat Enterprise Linux server. Oracle database is 10g. (15 Replies)
Discussion started by: shellguy
15 Replies

4. Shell Programming and Scripting

Reading and analysing data in a text file

Hi, I have below type of data in a text file in unix. Emp_Name Emp_Dept Raj 101 Amruta 100 Shilpa 100 Rohit 123 Amol 198 Rosh 101 Gaurav 198 Number of employees can be even more. Need a command or a... (2 Replies)
Discussion started by: rajneesh_kapoor
2 Replies

5. Web Development

INSERT data to a Database Table from a text file

If you have a text file and if you want to Insert data to your Database Table, You can do it with these queries LOAD DATA LOCAL INFILE '/path/yourTextFile.txt' INTO TABLE yourTableName FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' (0 Replies)
Discussion started by: sitex
0 Replies

6. Shell Programming and Scripting

Reading data from DataBase and Writing to a file

Hi All, Please help me in writing data to a file in one row. In database there is a column which contains large data which does not fit in the file in one row. The column contains list of paths. I want to write these paths to a file in one row. Please find the code below writes : ... (2 Replies)
Discussion started by: rajeshorpu
2 Replies

7. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

8. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

9. Shell Programming and Scripting

How to insert data into MYSql database from a text file

Hi, Need to get help from you guys about this issue. I need to insert data into MySql database from a text file which is located in other server. The text file is something look like below: Date | SubscriberNo | Call Duration 20/7/07 | 123456788 | 20 20/7/07 | 123412344 | 30 The... (4 Replies)
Discussion started by: shirleyeow
4 Replies

10. Shell Programming and Scripting

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 ... (9 Replies)
Discussion started by: forevercalz
9 Replies
Login or Register to Ask a Question