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 02: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 Search this Thread Display Modes
  #8  
Old 12-20-2005
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
What database are you using (mySQL, informix, DB2)? What shell?
If your records are all fixed width, you may be able 'prep' it before loading..if not, you may need to rethink the problem.
Let me know.
Reply With Quote
Forum Sponsor
  #9  
Old 12-20-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Since you are considering using SQL Loader, I would guess that you are using Oracle. The usual method is to load the data into a set of temporary tables. Then write some PL/SQL code to read through the temporary tables to reformat and insert into your table. This method works well with very large data sets.

An alternative method is to bypass SQL Loader + Pl/SQL by using awk to create an "insert" script. Like this...
Code:
$ cat Bukom.awk
BEGIN {
  ins = "INSERT INTO bukom_table (locn, date, hour, strength) VALUES"
}
{
   for (i=3; i<=NF; i++) {
      printf "%s ('%s', %s, %s, %s);\n", ins,\
             $1, $2, sprintf("%02d%02d", int((i-3)/2), int((i-3)%2)*30), $i
   }
}

$ awk -f Bukom.awk Bukom.txt
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060101, 0000, 2.5);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060101, 0030, 2.6);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060101, 0100, 2.7);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060101, 0130, 2.8);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060101, 0200, 2.9);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060101, 0230, 2.3);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060101, 0300, 2.1);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060102, 0000, 2.4);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060102, 0030, 2.5);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060102, 0100, 2.6);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060102, 0130, 2.7);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060102, 0200, 2.7);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060102, 0230, 2.6);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060102, 0300, 2.4);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060103, 0000, 2.1);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060103, 0030, 2.3);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060103, 0100, 2.5);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060103, 0130, 2.6);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060103, 0200, 2.7);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060103, 0230, 2.7);
INSERT INTO bukom_table (locn, date, hour, strength) VALUES ('BUKOM', 20060103, 0300, 2.6);
There is a significant performance trade-off using this method over SQL Loader.

Last edited by Ygor; 12-20-2005 at 07:13 PM.
Reply With Quote
  #10  
Old 12-20-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
hi ygor :P yes im using oracle..thanks for you effort in helping me with this scripts..you totally understand my problem..thanks...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:34 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