fembot
fembot

Reputation: 87

How to display only the db2 query result via shell script and not the query?

There is probably a very simple solution here, but I am probably not using the right search terms. I have a sql query running in a shell script. I get the results I am looking for, however, I am also getting the sql query as part of of the result. How can I suppress this and just show the result?

My script:

#!/usr/bin/sh

db2 connect to MYDB >/dev/null 2>&1;
db2 -x -v "select A, B, C from MYTABLE";
db2 connect reset >/dev/null 2>&1;

And my output looks like this:

select A, B, C from MYTABLE
AAA   BBB   CCC
AAA   BBB   CCC

I would like to get rid of the first row and just show the result. What am I missing?

Thanks in advance for your help!

Upvotes: 0

Views: 6676

Answers (3)

Ian Bjorhovde
Ian Bjorhovde

Reputation: 11052

The -v option for the DB2 command line processor causes the current statement being executed to be printed in the output.

Remove the -v from your command and you'll get only the results of the query.

Upvotes: 3

Kent
Kent

Reputation: 195269

if you just want to skip the 1st row from your output you could:

yourscript.sh | tail -n +2

test with seq:

kent$  seq 5|tail -n +2  
2
3
4
5

Upvotes: 3

Related Questions