Select table name from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Select table name from file
# 1  
Old 02-15-2013
Select table name from file

i have a file tabel.out which contain table name in this format.

Code:
xyz
abc
qwe

Plz help me writing one script which actually takes tablename from file table.out file one by one and then select count (*) from $tablename limit 10; and print error in output file if any tabel is not accessible.


Thanks in Advance.Smilie
# 2  
Old 02-15-2013
Why don't you create a table in your DB containing the names and then run the query entirely in SQL?
BTW - could you explain the select count (*) ... limit 10; to me? count() should give one single line, shouldn't it?
# 3  
Old 02-15-2013
Thanks for update and that was typo mistake.correct count give row count value.

Code:
select * from $tablename limit 10;

well Our requiremnet is to check the first 10 rows of the table.we are getting tablename one by one from table.out files.
# 4  
Old 02-15-2013
Did you do an advanced search in these fora? There's loads of threads dealing with shell/SQL interaction.
# 5  
Old 02-15-2013
Use a while loop to read table name one by one into variable: tablename from file: table.out
Code:
while read tablename 
do
     # Connect to DB & query table: $tablename here
done < table.out

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Short program to select lines from a file based on a second file

Hello, I use UBUNTU 12.04. I want to write a short program using awk to select some lines in a file based on a second file. My first file has this format with about 400,000 lines and 47 fields: SNP1 1 12.1 SNP2 1 13.2 SNP3 1 45.2 SNP4 1 23.4 My second file has this format: SNP2 SNP3... (1 Reply)
Discussion started by: Homa
1 Replies

2. Shell Programming and Scripting

How to select the rows from oracle table using perl?

Hi, I am connecting to oracle database using perl. I am able to connect but i am not able to get all the rows from the table. Here is the code. #!/usr/bin/perl use DBI; my $dbh=DBI->connect("DBI:Oracle:student","class","welcome") or die "Couldnot connect oracle Database";... (1 Reply)
Discussion started by: vanitham
1 Replies

3. Shell Programming and Scripting

mysql how to select a specific row from a table

i have a table records ------------ id | user | time | event 91 admin | 12:00 | hi 92 admin | 11:00 | hi 93 admin | 12:00 | bye 94 admin | 13:00 | bye 95 root | 12:00 | hi 96 root | 12:30 | hi 97 root | 12:56 | hi how could i only select and display only the user and event from... (6 Replies)
Discussion started by: kpddong
6 Replies

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

5. Shell Programming and Scripting

Select older file if multiple file exists with same name

Hi I want to select older file if multiple files exist with same name. eg:There are five files in UNIX folder Sample1_20091231 Sample1_20100110 Sample1_20100115 Sample2_20100115 Sample3_20100115 However in file list i.e FileName.DAT I have data like Sample1 Sample2 Sample3 I am... (5 Replies)
Discussion started by: dashing201
5 Replies

6. Shell Programming and Scripting

select data from oracle table and save the output as csv file

Hi I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string,... (2 Replies)
Discussion started by: rdhanek
2 Replies

7. Shell Programming and Scripting

Select some lines from a txt file and create a new file with awk

Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (4 Replies)
Discussion started by: capnino
4 Replies

8. Shell Programming and Scripting

select a record from one file matching from second file using awk

I need help :) I have two input files and I'd like to generate a report based on the two. filea: hostname,account1,password ,account2,password hostname,account1,password hostname,account1,password ,account1,password ,account2,password repeating hostnames are blank fileb: hosta... (7 Replies)
Discussion started by: synmag
7 Replies

9. Shell Programming and Scripting

Extracting Table names from a Select Stament

Hi, I am working on a code to extract the table names out of a select statement. Is there anybody who has worked on something similar? May be you could provide me with the regular expression for the same. Regards. Silas (2 Replies)
Discussion started by: silas.john
2 Replies

10. Shell Programming and Scripting

Select last block from a file

Hi, I have to always select last portion of a block identified by 2 fixed keywords which repeats in a file for eg START .... ... END START .... ... END START .... ... END (9 Replies)
Discussion started by: misenkiser
9 Replies
Login or Register to Ask a Question