Sponsored Content
Top Forums Shell Programming and Scripting Insert value to ORACLE table from sqlldr log Post 302288884 by bakunin on Wednesday 18th of February 2009 08:21:34 AM
Old 02-18-2009
Quote:
Originally Posted by aimy
It's just that I feel my question is not that complicated but yet not one seems to answer..
One of the reasons questions get answered is the are "interesting" to solve: that means usually: non-trivial, non-obvious, complicated. Its an ironic fact that questions easy to be answered might take a longer time to actually be answered than the complicated and awkward ones.

Quote:
Originally Posted by aimy
While waiting for the solution, I take my own iniative to study a bit about awk utility.
That is exactly the right approach.


Quote:
Originally Posted by aimy
Code:
table_name = awk '/Table.+[:]/ {print substr($2,10)}' testfile.log
... rest snipped...

So, where i do went wrong in the script to set all that awk commands as a variable?
First off, your solution with awk is about the same line as my suggestion of sed - in this regard these two tools do about the same even if they do it in a somewhat different way.

Secondly there is a subtle syntactical error in your code: a variable assignment in shell scripts must not use blanks surrounding the "="-sign. Notice the difference between the two lines:

Code:
x = 100   # wrong
x=100    # correct

The reason is that the shell takes everything up to the "=" to be the variables name, hence when you write "x =" you are assigning a variable named "x " (x followed by a blank) and this is probably not what you intended.

Now for the main problem with your code, which is also of syntactical nature. You do NOT want to assign a string that resembles a command to the variable but you want the output of the command be assigned instead. Therefore you must tell the shell to execute the command separately first and then assign its output. Consider the following lines:

Code:
var=date
var=$(date)

The first line will assign the word "date" to the variable, the second one will first execute the "date"-command (whatever is between $(...) ) and execute it (in a separate shell instance, btw.). Whatever output is produced is then replacing the "$(....)" and only then the commandline is executed assigning the variable.

What does that mean to your problem? Edit the lines in the following way:
Code:
table_name="$(awk '/Table.+[:]/ {print substr($2,10)}' testfile.log)"

PS: some might suggest using backticks (`command`) instead of the $(command) construct. Backticks are an outdated way of basically achieving the same, but should be avoided because the newer construct is much more flexible and also better readable. It is one of the most prominent goals of shell scripting to produce code that is easily maintainable, easily read, easily understood. Backticks look in some fonts so similar to single quotes that because of this alone they should be abandoned. This being not the only disadvantage they have they should be avoided even more.

I hope this helps.

bakunin

Last edited by bakunin; 02-18-2009 at 09:28 AM..
 

9 More Discussions You Might Find Interesting

1. Programming

How can i load or insert a table in oracle from c language thru unix environment

I'm having a oracle server and i'm having a table in that. I'm having a linux server which is in network with the oracle server. I need to write a c program in linux env when on execution loads the table with the text file given as input. Please explain me the flow of process in that and also... (6 Replies)
Discussion started by: rramprasad
6 Replies

2. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

3. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time (Go to sleep mode) and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

4. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time then Go to sleep mode and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

5. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

6. Shell Programming and Scripting

Insert into Oracle table thru UNIX - linux 2.6.9-89

Hi, I am trying to insert a record into a table (say dips_tbl) which resides in Oracle DB through a ksh script. I want to insert records into few of the table columns-not all. I'll give an e.g. for the date column "CREATE_DATE". For that I first execute SQL1="SELECT SYSDATE FROM DUAL" ... (1 Reply)
Discussion started by: dips_ag
1 Replies

7. Shell Programming and Scripting

Insert script result into Oracle Table

Hi All, I want to insert STAT and ENDTIME values for each job in joblist into TBL_DAILY_STATUS table. Eg: insert into tbl_daily_status values(STAT,ENDTIME); Please help me on this. #!/bin/ksh joblist="com_abc_job com_abc_dot_job com_abc_seq com_abc_det" for i in $joblist do... (8 Replies)
Discussion started by: vichuelaa
8 Replies

8. UNIX and Linux Applications

Help in copying table structure to another table with constraints in Oracle

hi, i need to copy one table with data into another table, right now am using create table table1 as select * from table2 i want the constraints of table1 to be copied to table2 also , can anyone give me some solution to copy the constraints also, now am using oracle 10.2.0.3.0... (1 Reply)
Discussion started by: senkerth
1 Replies

9. Shell Programming and Scripting

Script to create the SQLLDR control file from Oracle table.

I need to create the shell script load the few 100 table using the SQLLDR. Need to generate the control file for each table using oracle table. table has "table names" and "column names" using this need create the control file. example table rows below table_nme column_nme DEPT ... (2 Replies)
Discussion started by: pimmit22043
2 Replies
All times are GMT -4. The time now is 06:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy