The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find a count of a word within a file bd_joy Shell Programming and Scripting 9 07-14-2008 09:29 AM
Script to find all the files that contain any of the words present in another file tsanthosh Shell Programming and Scripting 4 05-21-2008 02:29 AM
grep all records in a file and get a word count -perl meghana Shell Programming and Scripting 4 02-13-2008 10:06 PM
Count No of Records in File without counting Header and Trailer Records guiguy Shell Programming and Scripting 2 06-07-2007 12:15 PM
find and group records in a file thumsup9 UNIX for Advanced & Expert Users 20 04-19-2007 05:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-29-2007
navojit dutta navojit dutta is offline
Registered User
  
 

Join Date: Jul 2007
Location: Singapore
Posts: 32
To find the count of records from tables present inside a file.

hi gurus,

I am having a file containing a list of tables.i want to find the count of records inside thes tables.
for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file.

script :
for line in `cat tablenames`
do
#echo $line
sqlplus -s username/password@dbname << ! > table_count
set lines 1000 pages 0
declare
tab_name varchar2(50);
begin
tab_name:=$line
select count(*) from tab_name;
end;

!
done


but the table_count turns out to be = 0 after this executes....
Can anyone provide me with the correct approach.Its urgent.
  #2 (permalink)  
Old 08-29-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Try this:

Code:
nawk -v v="'" '{ print("select " v ":" $1":" v "||count(*) from "$1";"); }' tablenames > count.sql

sqlplus -s username/password@dbname <<! > count.log
set linesize 1000 pagesize 0 heading off feedback off trimspool on;
@count.sql
!

grep "^:" count.log
In the log file you will have the output in this format:

Code:
:TABLE1:10
:TABLE2:20
:TABLE3:30
...
:TABLEn:<count>
In this manner you can easily grep/cut the information you need from the log file.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0