简体   繁体   English

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

[英]How to capture hbase shell's output from shell script

I need to fetch records from hbase shell and print it to the output file below is what i have 我需要从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

When i try the above i get 当我尝试以上内容时

** **

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

** **

how do i eliminate those and just lines and just get below printed to the output 我如何消除那些和仅线条,并得到下面打印到输出

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

If you want to write the output to the file but skip the first part (7 lines), you can use tail for that job: 如果要将输出写入文件,但跳过第一部分(7行),则可以将tail用于该作业:

echo "${out}" | tail -n +7 >> /results_${table_name}_${DATE_TIME}.txt 

The + sign indicated to tail that you wan't to skip N lines. 尾部的+号表示您不希望跳过N行。 From tail --help : 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

Edit: Oh, and if you want to remove the last time too: 编辑:哦,如果您也想删除上一次:

echo "${out}" | tail -n +7 | head -n -1 >> /results_${table_name}_${DATE_TIME}.txt 

Basically the same thing, just the other way around. 基本上是同一件事,反之亦然。 For completeness, head --help : 为了完整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.

相关问题 如何在Shell脚本中的变量中捕获te.net命令的output - How to capture the output of telnet command in a variable in Shell script 并行运行两个shell脚本并捕获它们的输出 - Run two shell script in parallel and capture their output 如何使用Shell脚本加载Hbase表 - How to load Hbase table with shell script 如何捕获从Shell脚本引发的错误并以Groovy显示它? - How to capture error thrown from shell script & display it in groovy? 如何从 Shell 脚本的 HH:MM 格式的参数中捕获值 - How to Capture Values from an Argument in HH:MM Format for a Shell Script 如何根据第一个脚本的结果从另一个shell脚本调用shell脚本? - How to call a shell script from another shell script based on the first script's result? 将命令输出回显到终端的 shell 脚本 - A shell script that echo’s the commands output to the terminal 有没有一种方法可以捕获命令的输出,并将其返回值转换为Shell脚本中的变量? - Is there a way to capture the output of a command, and its return value into variables in a shell script? 如何从Shell脚本的命令输出中grep以获得字符串模式? - How to grep for a string pattern from command output in shell script? Executing shell script from another shell script &amp; Checking for a particular string from the output of invoked shell script - Executing shell script from another shell script & Checking for a particular string from the output of invoked shell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM