Netezza query in UNIX script without headers


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Netezza query in UNIX script without headers
# 1  
Old 08-04-2014
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,

Code:
Column_name
--------------------
2014:08:01 12:51:00

i just want the last line which is "2014:08:01 12:51:00"

the command i'm using inside the script is
Code:
nzodbcsql -h <hostname> -d <db name> -u <userid> -pw <pwd> -q "select MAX(startdate) from tablename";

i need to get the date in a vairable,

can someone please help me

thanks
MJ
# 2  
Old 08-04-2014
You're going to want to do you queries eliminating column headings. Supposedly -t does this. See reference: http://www-01.ibm.com/support/knowle...s.html?lang=en
Once you do that assigining the result is something like...
Code:
var=`
nzodbcsql -h <hostname> -d <db name> -u <userid> -pw <pwd> -q "select MAX(startdate) from tablename";'
or
var=$(nzodbcsql -h <hostname> -d <db name> -u <userid> -pw <pwd> -q "select MAX(startdate) from tablename";)

You could also do append a tail -1, like...
Code:
var=$(nzodbcsql -h <hostname> -d <db name> -u <userid>  -pw <pwd> -q "select MAX(startdate) from tablename"; | tail -1)


Last edited by blackrageous; 08-04-2014 at 02:28 PM..
# 3  
Old 08-04-2014
thanks a lot
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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 var=$(nzodbcsql -q "select MAX(millcount) from table1";) echo $var it returns the value like... (10 Replies)
Discussion started by: maximus_jack
10 Replies

2. Shell Programming and Scripting

PROBLEM WITH ORACLE QUERY IN UNIX SCRIPT

hi Guys, i have a problem with oracle query in my unix script.. I'm getting the following error while executing.. ./logtab.sh: sqlplus -s "pmutv/pmutv1" << EOFSQL^Jset head off^Jinsert into... (2 Replies)
Discussion started by: apple2685
2 Replies

3. Shell Programming and Scripting

SQLPLUS query in Unix script

Hi, I am using sqlplus query to get results in a csv format in unix. I am using ksh, and below is the query. echo "select r.num|| ',' || p.path ||',"' || r.issue_description ||'",' ||p.timestamp from events r, messagepath p;">> $QUERY_FILE sqlplus -s $LOGIN @ $QUERY_FILE>>$OUTFILE ... (2 Replies)
Discussion started by: Nutan
2 Replies

4. Shell Programming and Scripting

Execute SQL query in unix script

Hi I am new in unix. oracle and unix are installed in my sytem.i need the script which could connect to the oracle using username ,password and schema and can run the select * from tab query. Thanks vijay (8 Replies)
Discussion started by: vijays3
8 Replies

5. Shell Programming and Scripting

Merging of files with different headers to make combined headers file

Hi , I have a typical situation. I have 4 files and with different headers (number of headers is varible ). I need to make such a merged file which will have headers combined from all files (comman coluns should appear once only). For example - File 1 H1|H2|H3|H4 11|12|13|14 21|22|23|23... (1 Reply)
Discussion started by: marut_ashu
1 Replies

6. Shell Programming and Scripting

Unix script to run a query

Hi , I need help in creating the shell script for querying using a loop. I haev written the code as follows . But i am getting an error : Line doesn't required '(' . i have chagned but am getting again #!/bin/ksh ##checking the Command Line Parameter if test $1 = "" then ... (3 Replies)
Discussion started by: ramji_leo
3 Replies

7. Shell Programming and Scripting

Remove text between headers while leaving headers intact

Hi, I'm trying to strip all lines between two headers in a file: ### BEGIN ### Text to remove, contains all kinds of characters ... Antispyware-Downloadserver.com (Germany)=http://www.antispyware-downloadserver.c om/updates/ Antispyware-Downloadserver.com #2... (3 Replies)
Discussion started by: Trones
3 Replies

8. Programming

headers of the query

when we are spooling query o/p to certain txt file,in that file how we can get headers in the query.(through unix shell scripting). for exmple q1="slect * from XXXXXX;"; sqlplus XXX/XXXX@XXXXX spool XXXX.txt $q1 spool off in the text file i want the headers of the query..... ... (0 Replies)
Discussion started by: bhagya.puccha
0 Replies

9. Shell Programming and Scripting

A simple query on unix shell script

I want to write a script to go to particular path in file and run shell script from there. what will be shell script for the same. (2 Replies)
Discussion started by: shekhar_ssm
2 Replies

10. Shell Programming and Scripting

isql query in unix shell script

Dear all I want to execute some isql command from unix shell script. Kindly suggest me. isql command mention below. isql -U -P use gdb_1 go select count (*) from table_x go (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies
Login or Register to Ask a Question