shell—如何在unix中捕获变量中表的行计数

tgabmvqs  于 2021-06-24  发布在  Hive
关注(0)|答案(2)|浏览(239)
hive -e "select count (*) from table where year=2019 and month=04 and day=15"

这个命令给我的结果是15在下面的格式

+----+
| a  |
+----+
| 15 |
+----+

如何将值设为15而不是上述格式?

kzmpq1sx

kzmpq1sx1#

hive -e "select count (*) from table where year=2019 and month=04 and day=15" | grep -o '[0-9]*'

这个 -o 开关仅从输入输出该部分,该部分实际上与模式相对应。

tzcvj98z

tzcvj98z2#

下面的代码将对您有所帮助。

a=$(hive -e "select count (*) from table where year=2019 and month=04 and day=15")
echo $a

相关问题