![](/img/trans.png)
[英]How to capture the output of telnet command in a variable in Shell script
[英]How to capture hbase shell's output from shell script
我需要從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
如果要將輸出寫入文件,但跳過第一部分(7行),則可以將tail用於該作業:
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
,請head --help
:
-n, --lines=[-]NUM print the first NUM lines instead of the first 10;
with the leading '-', print all but the last
NUM lines of each file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.