0

I have a command and it returns 108 set of week/enumeration:

Command:

impala-shell -B -f query.sql

Results:

20180203        1
20180127        2
20180120        3
...

I parsed the results and read the week and enumeration as two variables. However, I have to use a variable wk to store intermediate results first:

wk="$(impala-shell -B -f query.sql)"
echo "$wk" | while read -r a b; do echo $a--$b; done

I tried to avoid using additional variable wk:

"$(impala-shell -B -f query.sql)" | while read -r a b; do echo $a--$b; done

But it returned:

...
20160213        104
20160206        105
20160130        106
20160123        107
20160116        108: command not found

I understand you can use wk="$(impala-shell -B -f query.sql)" && echo "$wk" | while read -r a b; do echo $a--$b; done but that doesn't avoid using a variable in the middle. How to compose a one-liner without using the variable wk?

1
  • 2
    Do you mean impala-shell -B -f query.sql | while read -r a b ; do echo $a--$b; done? Commented Mar 2, 2018 at 16:17

3 Answers 3

1

or awk to the rescue!

$ impala-shell -B -f query.sql | awk '{print $1"--"$2}'
Sign up to request clarification or add additional context in comments.

Comments

0

You can execute commands first (inline) when using special quotes ``

Try this (untested, as i neither have your shell, nor that script):

`impala-shell -B -f query.sql` | while read -r a b; do echo $a--$b; done

Comments

0

Most elegant answer goes to choroba in the question comments! You just need to remove the quotes!

impala-shell -B -f query.sql | while read -r a b ; do echo $a--$b; done

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.