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
# 8  
Old 08-18-2014
The echo without quotes must be hiding the true encoding of the contents of your output. Please change:
Code:
echo $var

to:
Code:
printf '%s\n' "$var" | od -c

# 9  
Old 08-18-2014
this is the output i received when i change to printf '%s\n' "$var" | od -c

Code:
0000000  \n       M   A   X      \n   -   -   -   -   -  \n       1   2
0000020          \n  \n   R   o   w   s       R   e   t   u   r   n   e
0000040   d       :       1  \n
0000046

meanwhile when i worked on the script, using the below code i was able to get only the value, but is there any better way to do that

Code:
var=$(nzodbcsql -q "select max(million_cnt) from tablename";)
echo $var
awk '{ print $1}' <<<"${var}" | head -4 |tail -1


Last edited by maximus_jack; 08-18-2014 at 11:38 PM..
# 10  
Old 08-18-2014
Or much more simply:
Code:
var=$(nzodbcsql -q "select max(million_cnt) from tablename";)
awk 'NR == 4{ print $1; exit }' <<<"${var}"


Last edited by Don Cragun; 08-18-2014 at 11:44 PM.. Reason: Strip private data
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 08-18-2014
thanks a lot don
appreciated

Cheers
MJ
 
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