I have a sqoop command in a shell script that returns a one column one row output like this:
Can you please help me with parsing this above output to get only the value 0? Thank you.
According to your image:
…you're needing the forlast line, right?
Piping the the output to tail -n 2
should answer
| 0 |
---------------
and from there pipe then to head -n 1
and voila.
Another approche can be to remove dash lines with `grep -v -e '^--*$' to have
| Identifier |
| 0 |
and from there, pipe then to tail -n 1
to retrieve the last line.
Finally, pipe to cut -d ' ' -f 2
or awk '{print $2}'
A refinement, if you want, will be to do the full stuff with sed
or awk
only.
If you are sure you have one column and two rows (the header and the data), the desired line is the fourth
1. ----------------
2. | Identifier |
3. ----------------
4. | 0 |
5. ----------------
So, with sed
just remove the leading "pipe-space" and trailing "spaces-pipe" of that line:
$sqoop_command | sed -e '4s/\(^| \)\|\( *|$\)//g'
Here, awk
may look easier when known:
$sqoop_command | awk 'FNR == 4 {print $2}'