read database tablename from another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read database tablename from another file
# 1  
Old 04-08-2011
read database tablename from another file

i hava a file which contains database like
Code:
 
emp
dept
loc

now i want to create a script that read this file line by line and create a seperate query that ll be run in database like..

DELETE FROM TRS_ONE_ATDE WHERE DATA_DT = <from file>

how can this be achieved. pls help.
# 2  
Old 04-08-2011
not sure if this is what you wanted:
Code:
kent$ cat t1.txt
emp
dept
loc

kent$ cat t2.txt
DELETE FROM TRS_ONE_ATDE WHERE DATA_DT = <from file>

kent$ awk 'FNR==NR{v[FNR]=$0} FNR<NR{o=$0; for(i=1;i<=length(v);i++) {$0=o;sub("<from file>",v[i],$0);print $0}}' t1.txt t2.txt
DELETE FROM TRS_ONE_ATDE WHERE DATA_DT = emp
DELETE FROM TRS_ONE_ATDE WHERE DATA_DT = dept
DELETE FROM TRS_ONE_ATDE WHERE DATA_DT = loc

# 3  
Old 04-08-2011
Or by this way..
Code:
awk '{print "DELETE FROM TRS_ONE_ATDE WHERE DATA_DT =", $0}' file.txt > outfile.txt

# 4  
Old 04-08-2011
hmm...well thanks.. but this dont seem to solve the purpose

its like

abc.txt
Code:
 
emp
dept
table2

and there is script already there..

Code:
export ORAUSER=`grep ORAUSER $PROJECT_HOME/parms/.itracs_pass|cut -c9-`
export ORASCHEMA=`grep ORASCHEMA $PROJECT_HOME/parms/.itracs_pass|cut -c11-`
export ORAPSWD=`grep ORAPSWD $PROJECT_HOME/parms/.itracs_pass|cut -c9-`

#-- Execute the SQL
delete from test WHERE DATA_DT = ????;
commit;


this delete SQL command should pick value from that .txt file and run the query..
# 5  
Old 04-08-2011
Quote:
While read line
do
echo "DELETE FROM TRS_ONE_ATDE WHERE DATA_DT =", $line >> $SCRIPT_FILE
done < $DBLIST
# 6  
Old 04-08-2011
Code:
awk 'FNR==NR{v[FNR]=$0} FNR<NR{o=$0;if($0~/<from file>/) for(i=1;i<=length(v);i++) {$0=o;sub("<from file>",v[i],$0);print $0}else print $0}' t1.txt t2.txt
export ORAUSER=`grep ORAUSER $PROJECT_HOME/parms/.itracs_pass|cut -c9-`
export ORASCHEMA=`grep ORASCHEMA $PROJECT_HOME/parms/.itracs_pass|cut -c11-`
export ORAPSWD=`grep ORAPSWD $PROJECT_HOME/parms/.itracs_pass|cut -c9-`

#-- Execute the SQL
delete from test WHERE DATA_DT = emp;
delete from test WHERE DATA_DT = dept;
delete from test WHERE DATA_DT = loc;
commit;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Creating script to read many files and load into database via single control file

Hi, I have many files but with only 2 names , I want to load the data of that file into database through sqlldr with single control file. how can i do that ????? Example: switch_file switch_file billing_file billing_file now these files should be loaded into same database but different... (1 Reply)
Discussion started by: niti_sharma
1 Replies

2. Shell Programming and Scripting

Read latest log files and perform database insert

Hi Experts, I have a situation where I need to write a shell script to continuously monitor a log directory with multiple log files and perform following: 1. Read the latest log file continuously and grep "Success" OR "Failure" 2. As it capture either Success or Failure, it has to perform a... (1 Reply)
Discussion started by: rish_max
1 Replies

3. 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

4. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

5. Shell Programming and Scripting

Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable

Hi All, I have browsed through the forums for a similar topic, but there is no topic which explains about this problem, when the backend is DB2. I want to assign the output of a select count(*) from tablename to a unix variable in a shell script. I am using ksh. The database used to... (3 Replies)
Discussion started by: Siddarth
3 Replies

6. Shell Programming and Scripting

To Read a File and Insert a part of the lines into the database

Hi Guys I need to have a shell script which reads a log file and insert a part of each line into the database. Some sample lines in the file are as below. 20091112091359 MED_RQACK : user_data=60173054304,100232120,20091112091359,;ask_status=0;ask_reason=OK;msg_id=20091112091319... (5 Replies)
Discussion started by: Somanadh
5 Replies

7. Shell Programming and Scripting

How to pass a date read from database to the shell script?

Hi i have a database table which i will query in a sqlplus session and it will either come back with a date or null? Now, what i want to do is based on the date returned i will either abort or continue with the script execution. I need to know is there a way other than spooling the date... (4 Replies)
Discussion started by: vinoo128
4 Replies

8. Shell Programming and Scripting

Pass tablename as a parameter in the Control File -- sqlldr

Just wanted to know if there is a way to pass the table name as a parameter in the control file. I have two tables...Table A and Table B. LOAD DATA append INTO TABLE TABLE_B FIELDS TERMINATED BY X'09' OPTIONALLY ENCLOSED BY '"' AND '"' TRAILING NULLCOLS Rather than hard coding... (1 Reply)
Discussion started by: madhunk
1 Replies

9. UNIX for Dummies Questions & Answers

Read SQL database from Unix...

Hi there, I am new here and looking for a bit of help... I don't don't know much about Unix but I've tried to include as much info as possible. We currently operate our system as a bespoke on SCO 5.05 with Informix databases. This includes a financials package called "Multisoft". Both... (0 Replies)
Discussion started by: uptheposh
0 Replies

10. Shell Programming and Scripting

PERL: Read from Database and copy

I have a microsoft access database with anout 220 lines. theres a question and 4 option awnsers and only ones correct which is also listed in th database. Is there any perl script that will copy and the lines from the database and put into a .asp website ? (2 Replies)
Discussion started by: perleo
2 Replies
Login or Register to Ask a Question