How to execute a no of SELECT COUNT(*) statements using a loop
HI Unix Gurus,
I have a number of SELECT count(*) statements in an input file and I want to execute it using a shell script but one by one using loop in script....
How can I do this.....
I can have a number of Select count(*) statements in an input file....it may be only 1 more more than 1, number of statements is not fixed...
So I want to use a loop thru which i can check the count of 1 statement and if it is greater than 100,000 then i will stop processing....this is requirement
I can grep the number of SQLs present in input file but I want to run 1 sql at a time instead of running them all...
You're really NOT making it easy by not copying an example of what your file could look like! What is your problem with that? If I understand well, the Select count(*) statements are buried in the middle of other statements. Right? Do they always occupy a full line? Can they be split between several lines? Do they have the trailing semicolon?
What if there are 150,000 statements? Do you want to process the first 100,000 statements? or nothing at all?
Why do you want to use a loop?
is exactly the same thing as
If the idea is to process the first 100,000 statements, and considering one statement = one line, I would just do the following:
If you want more help, provide more information.
This User Gave Thanks to chebarbudo For This Post:
I am sorry but cannot paste my code here due to some compliance issues...hope you understand.....
to make it simple, i'll give you an example.....
input file would contain...
Select count(*) from employee where dept=10;
Select count(*) from employee where dept=20;
Select count(*) from employee where dept=30;
Select count(*) from employee where dept=40;
Select count(*) from employee where dept=50;
Select count(*) from employee where dept=60;
Select count(*) from employee where dept=70;
Select count(*) from employee where dept=80;
Select count(*) from employee where dept=90;
Number of SQLs may vary from 1 to any number.....here i took it randomly 9 SQLs.....
Now I want to execute this input file thru a unix script but I want to execute first SQL first and if the result of first SQL is greater than 100,000 then stop processing...
That's better. Of course I was not expecting you to paste the full or real code. But this template helps a lot!
In this case, I think that's what you want to do:
Be careful, if one of the statement outputs more than one line, an error will occur. For example if you insert another field or a GROUP BY.
Hello Forum,
I'm looking to expand the following command:
INACTIVE_KERNELS=$(python -mplatform | grep -qi red && rpm -qa | grep '^kernel-' |grep -vE `uname -r` | paste -sd \; || echo "Not Red Hat Server")
Currently this command will check if my server is RedHat server using the grep -qi... (6 Replies)
Say I have a for loop that parse through a file....Say it look for the colors red and blue in sections of the file. Say it find red before it find blue in the file.
Say I have two if statements in the for loop
Something like if blue is found print blue is my favorite color is the first if... (7 Replies)
Hi Everybody,
I wanna count lines in many files, but only if they meet a condition, I have something like this,
cat /path1/usr/STAT/GPRS/ESTCOL_GPRS_2016* | awk 'BEGIN{FS=",";}{ if (substr($5,1,8)=='$DATE'){a++} END{for(i in a)print a}}'
DATE=$(date +%Y%m%d -d "1 day ago")
But it has... (6 Replies)
Bash shell, variables i and rem are working fine in 2 separate for loops, but I'd like to consolidate them like this:
for && This gives syntax error on &&.
Thanks in advance for direction. (5 Replies)
Hello fellow awkers,
I am trying to combine the following awk statements into 1 so that the results are more accurate:
awk '/\=\+/ { count++ } END { print count}' filename
awk '/\=\?/ { count++ } END { print count}' filename
awk '/\=\-/ { count++ } END { print count}' filename
awk... (8 Replies)
how can we execute multiple statements in
else condition
i have
if
then
statement
else
statements
fi
in else condition i have multiple statements
but it executing only one statement
is there any way to execute multiple statements (4 Replies)
Hello All,
I am new to shell scripting. I am working on Solaris O/S, bash script and sybase programming.
I want to loop through multiple values in an array and for each value, I
want to select a row from the database.
following is the code written for it.
output="loop.csv" ... (8 Replies)
Please help me. I have been doing this for several hours.
Here is the code
if then
echo a b c d >> file.txt
echo 1111 >> file.txt
fi
The reason I want the two echo is because I want these statements printed on multiple lines. I keep getting error .
First it tells me... (2 Replies)
Hi,
Actually i stored all validdisks in one array and corresponding partitions required for all individual disks in other array..
Example:
Validdisks=dsk2 dsk3 dsk5
ValidPartition=4 4 3
Now i have to create domain..
Domain creation can be done by below commands:
fs_setup -d... (1 Reply)
New to scripting in general, so patience plz. If I ask a stupid question or don't get it, I thank you for your kindness in advance.
That said, did a for i loops checks to see if a PB* file is there but I need to know two things before I copy the file.
I need to know if the file's create date... (2 Replies)