ran16
1
Hi ,
Can anyone help me regarding loading a unix file data to oracle database table using shell scripts?
I wanted to grep only this data from a spool file
sql_test.txt
99
00:00:00:01
but if I use grep I am getting format
sql_test.txt
99 rows selected.
Elapsed: 00:00:00.01
convert the elapsed time to seconds and then
I want to load
sql_test.txt,99,00:00:00:01(converted to second like .0001 )
to a oracle table with columns
Query
rows
Elapsed
If your input file contains exactly this:
sql_test.txt
99 rows selected.
Elapsed: 00:00:00.01
You can obtain the insert statement by executing:
awk '
/rows selected/ { $0=$1 }
/Elapsed/ { split($2, t, ":"); $0=3600*t[1]+60*t[2]+t[3] }
{ out=out sprintf("%s%s", NR==1?"":",", "\047"$0"\047") }
END { print("insert into MY_TABLE values ("out");") }
' input_file.txt
The generated output is:
insert into MY_TABLE values ('sql_test.txt','99','0.01');
ran16
3
Thank you So much it worked.