Looping a flat file and loading data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping a flat file and loading data
# 1  
Old 01-07-2013
Looping a flat file and loading data

Hi, I am very new to UNIX environment. And I am stuck in this problem.

In my Unix server, I have a file called "tablelist.txt" which gives me a list of the tables in my oracle database like shown below.

bmp.table1
bmp.table2
bmp.table3
:
:
bmp.table20

All these tables have 'batch_id' column.

Now i need a Unix script which will loop through each line of tablelist file. and extract the data from each table for that batch_id and load into separate files.

At the end of the process, i should have 300 files which has records of 300 tables.

Note: I am using SQLPLUS In Unix server.
# 2  
Old 01-07-2013
Try this:
Code:
#!/bin/ksh
seq=1
while read table_name
do
  SqlOut=`sqlplus -s username/password@instance << EOF
  set echo off head off feed off pagesize 0 trimspool on linesize 1000
  spool batch_id_${seq}.txt
  select batch_id from ${table_name};
  spool off;
  exit;
  EOF`
  seq=$(( seq + 1 ))
done < tablelist.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting data from a flat file based on condition

Hi, I have a flaty file from which i am fetching few columns in tablular form as below code. Now i want to fetch the column 6 and 7 in below code only if it either of them is non zero.However below startement awk -F, '$6==0 && $7==0{exit 1}' ${IFILE} is not working..Not sure where is the... (36 Replies)
Discussion started by: Vivekit82
36 Replies

2. Shell Programming and Scripting

Data is available or not in a flat file generated by Oracle

Hello, please help me an the below issue. i need to check whether data is available or not in a flat file generated by oracle (sometimes sql didn't any records) to overcome this. without opening flat file. Thanks....... (1 Reply)
Discussion started by: mahesh1987
1 Replies

3. Shell Programming and Scripting

Creating loops inside a file and extracting and loading data

Help needed (1 Reply)
Discussion started by: Chand Shrestha
1 Replies

4. Shell Programming and Scripting

Reading XML data in a FLAT FILE

I have a requirement to read the xml file and split the files into two diffrent files in Unix shell script. Could anyone please help me out with this requirement. Sample file --------------- 0,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Information... (3 Replies)
Discussion started by: kmanivan82
3 Replies

5. Shell Programming and Scripting

To read a flat file containing XML data

I have a file something like this:aaaa.xml content of the file is 0,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <s> <BRANCH_NO>3061</BRANCH_NO> <BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME> ... (4 Replies)
Discussion started by: kmanivan82
4 Replies

6. Shell Programming and Scripting

Help with loading data from DB2 database to CSV file

Hi everyone!! I need help regarding this. How can we load data from DB2 Database tables into a Comma Separated File? I also have another Question? Using Shell scripting, Is it easy to read Data from a table or from a text file? It is very urgent for me. Please help me out guys. ... (1 Reply)
Discussion started by: ss3944
1 Replies

7. Shell Programming and Scripting

Load data from a flat file to oracle.

I have a flat file with records like Header 123 James Williams Finance2000 124 Pete Pete HR 1500 125 PatrickHeather Engg 3000 Footer The structure is: Eno:4 characters Name:8 characters Surname : 9 characters Dept:7 characters Sal:4characters These are sample... (1 Reply)
Discussion started by: Shivdatta
1 Replies

8. Shell Programming and Scripting

Loading Oracle data to unix in flat file

Hi I would like to know how to load oracle data to unix flat file using a shell script. Can we use sqlldr to import data from oracle, if so can anyone help me with it. (2 Replies)
Discussion started by: raghav288
2 Replies

9. Shell Programming and Scripting

unix script for loading a data from a file into database

Hi All, I am trying to load a data from a files in a particular directory to a database.. cd $SCC isql metdb >> ${LOGDATA}/LOAD.LOG < ! load from "${LDATA}/${FORM}.ld" insert into $LOADTABLE ! But it's showing the error "syntax error at line 46 : `<<' unmatched" Can u plz help me... (5 Replies)
Discussion started by: grajesh_955
5 Replies

10. Shell Programming and Scripting

Help with Data Positioning from Columns in a flat file.

Hi All, I have used this forum many times to solve my many scripting problems. This time, I would like to seek some answers to a problem that I've been head scratching quite a bit on. My Example: I am converting a 2000-byte file into a 300-byte file this file has no delimiters and hardly any... (3 Replies)
Discussion started by: oott1
3 Replies
Login or Register to Ask a Question