Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
My query is as follows:
(1) I want to write a Schell Script which will first read multiple files.Each file contains multiple lines/records.
(2) Each line /record in a file starts with 'H' , 'D' or 'P'
(3) So want a shell script - which will read the FIRST CHARACTER of each line in a file.
(4) If the first character is 'H' , it will insert that line/record in database TABLE1
(5) If the first character is 'D' , it will insert that line/record in database TABLE2
(6) If the first character is 'P' , it will insert that line/record in database TABLE3So depending on the FIRST CHARACTER of each line in a file , that line/record will be inserted into different oracle database tables.
-- Abhay
--Abhay

Hi ,
I am just putting a sample of the Lines in a file:H|820020080422|AAA|03/27/2008|3.0.5
D|99.114|ADLT|1|60.00||60.00|60.00
D|99.683|ADLT|1|28.00||28.00|28.00
P|03/27/2008|CS|KKKK|HHHHH|||70.00
P|03/27/2008|CC|kkk|kkkk|1111||18.00
P|03/27/2008|CS|KKKK|HHHHH|||-28.00So shell script will read each line and then depending on first character of the line - will insert into different tables.
Thanks
--Abhay

Your shell script cannot insert into Oracle tables. SQL*Loader (sqlldr) can read your file and insert into the various tables.

if you can download and install gawk from here:
http://gnuwin32.sourceforge.net/pac...save the below code as script.awk
BEGIN{FS="|";q="\047"}
/^H/{ t=table1}
/^D/{ t=table2}
/^P/{ t=table3}
{
sql="insert " t "values("q$1q","q$2q","q$3q","q$4q","q$5q")"
cmd="sqlplus blah blah " sql
print cmd
# system(cmd) #uncomment when needed.
}on the command line:
c:\test> gawk -f script.awk inputfile
sqlplus blah blah insert values('H','820020080422','AAA','03/27/2008','3.0.5')
sqlplus blah blah insert values('D','99.114','ADLT','1','60.00')
sqlplus blah blah insert values('D','99.683','ADLT','1','28.00')
sqlplus blah blah insert values('P','03/27/2008','CS','KKKK','HHHHH')
sqlplus blah blah insert values('P','03/27/2008','CC','kkk','kkkk')
sqlplus blah blah insert values('P','03/27/2008','CS','KKKK','HHHHH')of course, i have created a fictitious command for inserting your tables. you have to modify it your own to use with oracle(?) , accordingly.

![]() |
U guys R great! One more ...
|
option to run file that w...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |