0

I have a set of commands in a bash script, eg running a query in impala.

#! /bin/sh
RESULT=`impala-shell -q "select count(*) from testable"`

The result of the shell script is.

Starting Impala Shell without Kerberos authentication
Connected to mycomp.cool-cluster.com:21000
Server version: impalad version 2.0.0-cdh5 RELEASE (build 12323323)
Query: select count(*) from enriched_call
Fetched 1 row(s) in 0.62s
+----------+ | count(*) | +----------+ | 234343 | +----------+

I would want to get only the value from this output ie, 234343 and try to assert the count in a script using Regex, split etc.

If I try to eliminate non numeric vaules, numbers from the version also come in. I want to split by say '|' and get the value 234343

2 Answers 2

2

Try doing this :

RESULT=$(
    impala-shell -q "select count(*) from testable" |
        awk -F'|' 'END{print $4}'
)
Sign up to request clarification or add additional context in comments.

Comments

0
RESULT=$( impala-shell -q "..." | tail -n 1 | grep -o '[[:digit:]]\+' )

or

RESULT=$( impala-shell -q "..." | sed -n '$s/[^[:digit:]]//gp' )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.