linux - 如何从 shell 脚本捕获 hbase shell 的输出

标签 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

最佳答案

如果你想将输出写入文件但跳过第一部分(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

关于linux - 如何从 shell 脚本捕获 hbase shell 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52297795/

相关文章:

r - 如何在 Linux 上从 R 访问 Olap-Cubes

windows - AppEngine SDK for Go with Bash on Ubuntu on Windows

perl - bash 通过匹配列合并文件

linux - 信息索引(emacs 内和外)

linux - "sudo -i"和 "sudo su -"有什么区别

linux - 如何排除第一列和第二列具有相同值的行?

linux - 如何提取列以释放命令

linux - 将进程固定到 CPU 内核或 SMP 节点是否有助于减少缓存一致性流量?

bash - 如何在 awk 脚本中使用 shell 变量?

linux - 使用 SED 命令删除 Markdown 文件中的代码块