如何从Shell脚本捕获HBase Shell的输出

时间:2018-09-12 14:38:54

标签: linux bash unix sh

我需要从hbase shell获取记录并将其打印到输出文件中 以下是我所拥有的

while IFS="=" read name value
do
query=$(echo "get '/tables/${table_name}','${value}',{COLUMNS=>['cf2:CDC_TS','cf2:CDC_FLAG','cf:ROW_STS_CD']}" | hbase shell ) 
OUT=`tail "$query"`
echo "${OUT}" >> /results_${table_name}_${DATE_TIME}.txt
done < /Hbase_retrieve.properties

当我尝试上述操作时,我会得到

**

HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.1.8-mapr-1710, r2c52ca3f992cced95f36b11d7b04b86474ad9ed0, Sun Nov 12 23:59:09 UTC 2017

Not all HBase shell commands are applicable to MapR tables.
Consult MapR documentation for the list of supported commands.

get '/tables/$table_name','row_key',{COLUMNS=>['cf2:CDC_TS','cf2:CDC_FLAG','cf:ROW_STS_CD']}
COLUMN  CELL
 cf:ROW_STS_CD timestamp=1506562033493, value=A
 cf2:CDC_FLAG timestamp=1506562033493, value=U
 cf2:CDC_TS timestamp=1506562033493, value=2017-09-27 20:27:13.493
3 row(s) in 0.1990 seconds

**

我该如何消除这些而已,而仅消除下面的行并打印到输出中

get '/tables/$table_name','row_key',{COLUMNS=>['cf2:CDC_TS','cf2:CDC_FLAG','cf:ROW_STS_CD']}
COLUMN  CELL
 cf:ROW_STS_CD timestamp=1506562033493, value=A
 cf2:CDC_FLAG timestamp=1506562033493, value=U
 cf2:CDC_TS timestamp=1506562033493, value=2017-09-27 20:27:13.493

1 个答案:

答案 0 :(得分:1)

如果要将输出写入文件,但跳过第一部分(7行),则可以将tail用于该作业:

onSubmit(value)

echo "${out}" | tail -n +7 >> /results_${table_name}_${DATE_TIME}.txt 符号指示您不想跳过N行。来自+

tail --help

编辑:哦,如果您也想删除上一次:

-n, --lines=[+]NUM       output the last NUM lines, instead of the last 10;
                         or use -n +NUM to output starting with line NUM

基本上是同一件事,反之亦然。为完整起见,echo "${out}" | tail -n +7 | head -n -1 >> /results_${table_name}_${DATE_TIME}.txt

head --help