hbase根据rowKey范围批量删除

脚本三个参数 :表名 startRow endRow
#!/bin/bash
tablename=$1
startrow=$2
endrow=$3
if [ $# -eq 0 ];then
echo "请输入表名,startRow,endRow"
exit 0
fi
echo "scan '${tablename}',{STARTROW=>'${startrow}',ENDROW=>'${endrow}'}" |hbase shell|awk -F ' ' '{print $1'\t'}'> ./file.txt
#删除前6行非表中数据
sed -i '1,6d' file.txt
#删除最后一行(空行)
sed -i '$d' file.txt
#删除最后一行(总条数)
sed -i '$d' file.txt
cat ./file.txt|awk '{print $1}'|while read rowvalue
do
echo -e "deleteall '${tablename}','${rowvalue}'" >> ./deleteRowFile.txt
done
rm ./file.txt
echo "exit" >> ./deleteRowFile.txt
#为避免线上执行失误 ,先检查deleteRowFile.txt中要删除的rowkey是否正确,所以以下两行命令请手动执行
#hbase shell ./deleteRowFile.txt
#rm ./deleteRowFile.txt

ps:
执行命令如:sh deleteHbaseByRow.sh zhfxtest  00000000144162571899616854252667 00000000144162571984514188501761
deleteRowFile.txt文件内容格式如下:


你可能感兴趣的:(HBase)