Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut the string before the first space

Tags:

shell

sql

I'm trying to cut the string before the first space as I want to get the value returned from the DB request assigned to MINOR_VER variable. The returned string is 3 1 row selected (overall time 6731 usec; server time 1281 usec) and I only need 3 as an output.

My approach is to get the string and pass it to cut, but so far I couldn't reach the goal.

MINOR_VER_QUERY="select count(*) from $DB_SCHEMA.RPT where CASE_UUID='3'"

MINOR_VER=$(echo `hdbsql -a -n $HOST -i $INSTANCE -u $DB_USER -p $DB_PWD $MINOR_VER_QUERY` | cut -d' ' -f1)

hdbsql is hana database sql cli to create a db connecntion.

like image 680
Ren Avatar asked Aug 27 '26 23:08

Ren


1 Answers

There is a -x flag available for hdbsql CLI that will drop the appended statistics from the returned result set. You may also find the -quiet flag to be helpful too. More info on available flags here

Instead:

MINOR_VER=$(hdbsql -x -quiet -a -n $HOST -i $INSTANCE -u $DB_USER -p $DB_PWD $MINOR_VER_QUERY)
like image 105
JNevill Avatar answered Aug 30 '26 12:08

JNevill