Grep SQL output file for greater than number.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep SQL output file for greater than number.
# 1  
Old 03-05-2014
Grep SQL output file for greater than number.

Hi, This is my first post.

I have a korn shell script which outputs a select statment to a file. There is only one column and one row which contains a record count of the select statement.

The select statement looks something like this:

Code:
 
 SELECT COUNT(some_field) AS "count_value" 
 FROM some_table                             
 WHERE status = '4'
 AND program_id like 'some_id'
 AND (time_added > 'now' - date('1 day'))

and the output file contains

Code:
 
INGRES TERMINAL MONITOR Copyright 2008 Ingres Corporation
Ingres SPARC SOLARIS Version II 9.2.1 (su9.us5/103) login
Wed Mar  5 15:44:34 2014
continue
* * * * * * /* SQL Startup File */
 SELECT COUNT(some_field) AS "count_value" 
 FROM some_table                             
 WHERE status = '4'
 AND program_id like 'some_id'
 AND (time_added > 'now' - date('1 day'))
Executing . . .
 
+-------------+
|count_value   |
+-------------+
|           13|
+-------------+
(1 row)
continue
* * 
continue
* * 
Your SQL statement(s) have been committed.
Ingres Version II 9.2.1 (su9.us5/103) logout
Wed Mar  5 15:44:34 2014

I would like to now send an email if the value of count_value is greater than '4' using an if statment. As I am fairly new to scripting, can anyone provide some guidence on the best method to do this please?

Regards,
MurdocUK
# 2  
Old 03-05-2014
Something like...
Code:
value=`awk '/^\|count_value/ {getline;getline;print $0}' sql.out | cut -f2 -d\|`
[[ ${value} -gt 4 ]] && echo "body of email" | mailx -s "Count exceeded" some_user@host

where sql.out is the file of sql output
# 3  
Old 03-05-2014
Code:
value=$( awk '/\| /{gsub(/\|| */,x);print}' sql.out )

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to output non-number lines with grep?

I want to check my data quality. I want to output the lines with non-number. I used the grep command: grep '' myfile.csv Since my file is csv file, I don't want to output the lines with comma. And I also don't want to output "." or space. But I still get the lines like the following:... (8 Replies)
Discussion started by: twotwo
8 Replies

2. UNIX for Beginners Questions & Answers

How do I use grep to grab prime number output from my factor program?

I have a factor program that runs and outputs to stdout all the prime numbers that are specified in the given paramters, in this case 30000000-31000000. Command: factor/factor 30000000-31000000 Sample output: 30999979 = 30999979 30999980 = 2^2 5 11 140909 30999981 = 3 10333327... (6 Replies)
Discussion started by: steezuschrist96
6 Replies

3. UNIX for Dummies Questions & Answers

Greater than specific number

please let me know how to construct if then else by comparing two numbers if it is greater than 10000. I need to do some specific task executed. can you help me out in shell scripting plz. (6 Replies)
Discussion started by: ramkumar15
6 Replies

4. Shell Programming and Scripting

Grep lines for number greater than given number

Hello, I am newbie to bash scripting. Could someone help me with the following. I have log file with output as shown below **************************LOG************************* 11/20/2013 9:11:23.64 Pinging xx.xx.xx.xx with 32 bytes of data: 11/20/2013 9:11:23.64 Reply from xx.xx.xx.xx:... (4 Replies)
Discussion started by: meena_2013
4 Replies

5. Shell Programming and Scripting

Egrep a number greater than in a column

i'm aware awk can do what i'm trying to do here. but i cant use awk in this scenario given the circumstance of this box. but i need to check if a number is a certain column is over a certain value, say for instance, 20. data: | 12 | 19 | 2000 | 9029333 |... (11 Replies)
Discussion started by: SkySmart
11 Replies

6. Shell Programming and Scripting

Egrep a greater than number

data: hello mr smith 400 you all ok? hello mrs. smith 700 you all ok? hello mr. everyone 150 you all ok? hello mr. you all 199 im lad you are ok using egrep, how can i grep out only lines that have a number greater than 250? cat data | egrep ..... can't use awk here. i was... (7 Replies)
Discussion started by: SkySmart
7 Replies

7. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

8. Shell Programming and Scripting

How to grep a pattern having value greater than 123 in a file?

Hi, I have a dynamically growing ascii file which has large data (both text and digits). I need to grep those lines having value greater than '123'. These numeric values may appear at anywhere in the line, hence I could not use awk to split to columns. So, please help me with the grep regular... (12 Replies)
Discussion started by: royalibrahim
12 Replies

9. UNIX for Dummies Questions & Answers

how to grep a number from output line

I`m having a output shown below, CFR 235,BBC DM-2 ALL CFR 111,BBC DM-2 ALL CFR 333,BBC DM-2 ALL from the above Output i want to use 235,111,333 as input for other purpose. these no always change every time i run script.so please suggest me the way i could do it with example,i have tried... (5 Replies)
Discussion started by: nitin_aaa27
5 Replies

10. UNIX for Dummies Questions & Answers

How to grep / zgrep to output ONLY the matching filename and line number?

Hi all, I am trying to zgrep / grep list of files so that it displays only the matching filename:line number and does not display the whole line, like: (echo "1.txt";echo "2.txt") | xargs zgrep -no STRING If I use -o option, it displays the matching STRING and if not used, displays the... (3 Replies)
Discussion started by: vvaidyan
3 Replies
Login or Register to Ask a Question