# !/bin/bash
# 功能:按时间查找相应列的数据量
# 开发人:jhy
# 输入参数据:$1库名 $2表名 $3列簇名 $4起始时间 $5截止时间 $6列名
# ps:sh hbase_select.sh huihuahua app_call_records app '2018-03-01 00:00:00' '2018-03-28 00:00:00' customer_id
# 按列名进行删除,必须删除所有列
if [ $# -lt 6 ];then
echo "wrong arg[] number"
exit 1
fi
ns1=$1
t1=$2
c1=$3
l1=$6
start_date="$4"
end_date="$5"
start_tm=`date -d "$start_date" +%s`
end_tm=`date -d "$end_date" +%s`
start_tm_rs=$((start_tm*1000+`date "+%N"`/1000000))
end_tm_rs=$((end_tm*1000+`date "+%N"`/1000000))
echo "scan '$ns1:$t1', { COLUMN => '$c1:$l1', TIMERANGE => [$start_tm_rs, $end_tm_rs]} " | hbase shell > ./hbase/001.txt
awk -F ":" '$1~/column/' ./hbase/001.txt > ./hbase/002.txt
#移除文件前6行
#sed '1,6d' ./hbase/001.txt > ./hbase/copy.txt
#mv ./hbase/copy.txt ./hbase/001.txt
#移除文件最后两行
#删除功能
#sed -i '$d' ./hbase/001.txt
#sed -i '$d' ./hbase/001.txt
#echo "exec hbase shell <<EOF" > ./hbase/002.sh
#cat ./hbase/001.txt|awk '{print "scan '\'$ns1:$t1\''", ",","'\''"$1"'\''",",","'\'${c1}:${l1}\''" }' >> ./hbase/002.sh
#echo "EOF " >> ./hbase/002.sh
#sh ./hbase/002.sh