linux - 如何从 shell 脚本中捕获 hbase shell 的输出
问题描述
我需要从 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
:
-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
推荐阅读
- python - 删除未命名的列熊猫数据框
- r-markdown - Xaringan 演示文稿的演示者模式不同步
- python - 继承 QGraphicsView 并使用 mouseMoveEvent 和 mouseClickEvent 在我的场景中移动 QGraphicsItems
- r - R中的不符合语法
- angular - 我不明白数据绑定在 Angular 中是如何工作的?
- asp.net-core - 在 ASP.Net Core 3.x 中禁用每个控制器的会话
- ruby - Sinatra 中参数哈希的奇怪行为
- flutter - 如何在导航到下一个屏幕之前让启动屏幕等待计算?
- android - onItemClick 的查看器初始化不起作用
- python - 在数据框中打印计数