在有时候,需要查询的表字段特别多,但是又不想写出这些字段?
使用如下的构建脚本。
实现了输出表的所有表头,并转换成逗号分隔的模式输出
#!/bin/sh
. /etc/profile
. ~/.bash_profile
SCRIPT_NAME=$0
echo ${SCRIPT_NAME}
# 从表中获取所有表头,形成单行字符串,用于构建HBASE中的列
# params table-name(exclude path)
# date 2017-11-15
# author zhangjianfei
# since 1.0.0
# 1. set workdir
WORK_DIR=`dirname ${SCRIPT_NAME}`
echo ${WORK_DIR}
cd ${WORK_DIR}
# 2. args check
if [ $# -eq 1 ]
then
TABLE_NAME=$1
else
echo "the args is wrong,you should give it like 'dg_user'"
exit 1;
fi
# 3. body
TABLE_SCHEMA_STR=`hive -e "desc $TABLE_NAME" | awk -F '\t' '{print $1,","}' | cat | xargs echo | sed s/[[:space:]]//g | awk '{sub(/.$/,"")}1'`
echo "$TABLE_SCHEMA_STR"
echo "$TABLE_SCHEMA_STR" > $WORK_DIR/tmp_schema.log
原文链接:https://www.f2er.com/bash/388943.html