To find the count of records from tables present inside a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To find the count of records from tables present inside a file.
# 1  
Old 08-29-2007
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  
Old 08-29-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Total record count of all the file present in a directory

Hi All , We need one help on the below requirement.We have multiple pipe delimited .txt file(around 100 .txt files) present on one directory.We need the total record count of all the files present in that directory without header.File format as below : ... (8 Replies)
Discussion started by: STCET22
8 Replies

2. Shell Programming and Scripting

Speed : awk command to count the occurrences of fields from one file present in the other file

Hi, file1.txt AAA BBB CCC DDD file2.txt abc|AAA|AAAabcbcs|fnwufnq bca|nwruqf|AAA|fwfwwefwef fmimwe|BBB|fnqwufw|wufbqw wcdbi|CCC|wefnwin|wfwwf DDD|wabvfav|wqef|fwbwqfwfe i need the count of rows of file1.txt present in the file2.txt required output: AAA 2 (10 Replies)
Discussion started by: mdkm
10 Replies

3. UNIX for Dummies Questions & Answers

How to find a string that is present in the file or not?

Im pretty new to shell scripting, but i have got the jist of it over the past 10 weeks or so i have been using it. I just have one thing im stuck on thats bugging the hell out of me. Here it goes... I need a script that - You enter a filename and then a string which reports whether that string... (2 Replies)
Discussion started by: Waggie14
2 Replies

4. Shell Programming and Scripting

How to count dup records in file?

Hi Gurus, I need to count the duplicate records in file file abc abc def ghi ghi jkl I want to get below result: abc ,2 abc, 2 def ,1 ghi ,2 ghi, 2 jkl ,1 or abc ,2 def ,1 (3 Replies)
Discussion started by: ken6503
3 Replies

5. Shell Programming and Scripting

Need unix commands to delete records from one file if the same record present in another file...

Need unix commands to delete records from one file if the same record present in another file... just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file.. tried with grep and while... (6 Replies)
Discussion started by: msathees
6 Replies

6. UNIX for Advanced & Expert Users

query display number lines or records present in file only numeric value -without filename

Hi all Thanks in advance........... Please help me for this issue............ I have a file it has 11 records . I used the command like .... >$ wc -l file 11 file I'm getting output like 11 file (no.of records along with filename) here my requirement is, I want to display only... (3 Replies)
Discussion started by: ksrivani
3 Replies

7. Shell Programming and Scripting

Automatically select records from several files and then run a C executable file inside the script

Dear list its my first post and i would like to greet everyone What i would like to do is select records 7 and 11 from each files in a folder then run an executable inside the script for the selected parameters. The file format is something like this 7 100 200 7 100 250 7 100 300 ... (1 Reply)
Discussion started by: Gtolis
1 Replies

8. UNIX for Dummies Questions & Answers

Count records in a zip file

Hello, I searched the forums on the keywords in the title I used above, but I did not find the answer: Is it possible to count records in a .zip file on an AIX machine if i don't have pkunzip installed? From all the research I'm reading in google and the reading of pkunzip in Unix.com,... (3 Replies)
Discussion started by: tekster757
3 Replies

9. Shell Programming and Scripting

grep all records in a file and get a word count -perl

Hi, I have a file .. file.txt .. i need to get a total record count in the files into a $variable.. im using perl script thanks (4 Replies)
Discussion started by: meghana
4 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question