Extract only the data from ksh script running netezza query


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extract only the data from ksh script running netezza query
# 1  
Old 08-18-2014
Extract only the data from ksh script running netezza query

Hi
I searched this forum before posting the question, but couldnt find it, the issue
i'm facing is, i'm trying to select a column from a netezza table from a korn
shell script, but the query runs
Code:
var=$(nzodbcsql -q "select MAX(millcount) from table1";)
echo $var

it returns the value like below from the script

Code:
MAX --------------------- 45 Rows Returned : 1

is it possible to just extract only the "45" from the output, one thing to note
here is, the output can sometimes be a 1 digit or 2 digit or a 3 digit value

thanks
MJ
# 2  
Old 08-18-2014
This is quite a basic problem, what have you actually tried so far?
# 3  
Old 08-18-2014
i tried this command
Code:
awk -F '{ print $3}' <<<"${var}"

but no luck on it, then i thought of using the cut command, but due to the
varying number of digits each time, that would be a problem,

what i'm trying to find is more of a versatile solution, like few syntax's, where the query only returns the data and no header values,
but as i'm having few library issues in the netezza unix environment, i'm not able to use the "nzsql" option, i have to live with the nzodbcsql option

i'm still trying for other ways, meanwhile if you could provide a solution
that would be a great help

thanks
MJ

Last edited by maximus_jack; 08-18-2014 at 06:26 PM.. Reason: added few more reasons
# 4  
Old 08-18-2014
By using -F the way you did, you have no script; only a very strange field separator. Simplify your script to just:
Code:
awk '{ print $3}' <<<"${var}"

# 5  
Old 08-18-2014
Hi
thanks for your response, i have tried that, it seems the query header, the underline and the data all seems to be considered as the first value, below is the script and the output
Code:
var=$(nzodbcsql -q "select max(cnt) from tablename";)
echo $var
awk '{ print $1}' <<<"${var}"

Output

Code:
MAX ----- 12 Rows Returned : 1

MAX
-----
12

Rows

Is it possible to get only the value "12"
# 6  
Old 08-18-2014
What happens if you change your script to what I suggested?:
Code:
var=$(nzodbcsql -q "select max(cnt) from tablename";)
awk '{ print $3}' <<<"${var}"

# 7  
Old 08-18-2014
Code:
var=$(nzodbcsql -q "select max(million_cnt) from IDM_DATALOAD_AUDIT where tablename = 'WI_PERSON'";)
echo $var
awk '{ print $3}' <<<"${var}"

output
------

Code:
MAX ----- 12 Rows Returned : 1





:

I'm getting only the ":" ( colon ) as the output
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regarding a query on making changes to a running script

Hello All, Greetings !! I have a query here to all is as follows: Question: Let's say we are running a script in a UNIX box and we have opened an another session and then made changes in script of some statements NOT to be print some values(just an example) so when I am monitoring the... (5 Replies)
Discussion started by: RavinderSingh13
5 Replies

2. UNIX for Dummies Questions & Answers

Netezza query in UNIX script without headers

Hi I'm trying run a netezza select query from a korn shell script, i'm getting the data in the below format, is there any way to get only the data in a vairable, Column_name -------------------- 2014:08:01 12:51:00 i just want the last line which is "2014:08:01 12:51:00" the command... (2 Replies)
Discussion started by: maximus_jack
2 Replies

3. Shell Programming and Scripting

Shell Script (ksh) - SQLPlus query filter using a string variable

Using ksh, I am using SQLPlus to execute a query with a filter using a string variable. REPO_DB=DEV1 FOLDER_NM='U_nmalencia' FOLDER_CHECK=$(sqlplus -s /nolog <<EOF CONNECT user/pswd_select@${REPO_DB} set echo off heading off feedback off select subj_name from subject where... (5 Replies)
Discussion started by: nkm0brm
5 Replies

4. Shell Programming and Scripting

Error in running DB query by script

Hi I was trying to fetch data from database. But the number of rows exported were huge so i got the error. Experts please advice. Thanks a lot for your supprt. #: ./script.sh ./script.sh: xmalloc: subst.c:3076: cannot allocate 1401346369 bytes (0 bytes allocated) (2 Replies)
Discussion started by: brij123
2 Replies

5. Shell Programming and Scripting

Running sed from a script query

Hello! I'm trying to run this code to print the body of an html document (all text in between <body> and </body>) from a script but am unsure how to call it from the command line interface. /<body>/,/<\/body>/ 1s/.*<body>// $s/<\/body>.*//p I have tried to call it using this: sed... (6 Replies)
Discussion started by: bgnersoon2be#1
6 Replies

6. AIX

Query on running script with nohup

Hi, I'm trying to run database restore script with the nohup command as it will run for long hours since if I run it normally, the putty session will become inactive and the restore gets terminated. The command I use is nohup db2 -tvf FBR_NODE0000.scr -z FBR_NODE0000.log & But the problem is... (2 Replies)
Discussion started by: vkcool.17
2 Replies

7. Shell Programming and Scripting

to find whether update query is successfull or not using Ksh Script

i have a script that performes an update operation. I just wanted to know whether that update statement is successfull or not. Below the script: #!/bin/ksh . $HOME/conf/systemProperties/EnvSetup.properties sqlplus -silent sie/da@edn.world <<END set pagesize 0 feedback off verify off... (3 Replies)
Discussion started by: ali560045
3 Replies

8. Shell Programming and Scripting

error ORA-06512 while running query in script

1 #!/bin/ksh 2 ################################################################ 3 # Written by Johnson 12/03/2008 4 # Version 1.0 5 # This script executes some SQL to provide Spike Check Report to TNS team. 6 ... (3 Replies)
Discussion started by: shivanete
3 Replies

9. Windows & DOS: Issues & Discussions

Running KSH script In SFU

I tried to run my ksh scripts in SFU and it always says "not found" as in the example below: $ .file /bin/ksh: .file: not found Did I miss something in the SFU Installation? (2 Replies)
Discussion started by: ilak1008
2 Replies

10. Shell Programming and Scripting

passing result of query to a varibale in ksh script

Hi, I have a scenario where in i have to extarct max of one column and pass it to a variable. i have tried to export the result as .dat file and read from that file.But my database is mainframe and it is not permitting me to export in .dat file.I have tried using .ixf file but reading from... (2 Replies)
Discussion started by: ammu
2 Replies
Login or Register to Ask a Question