如何在此配置单元查询中使用shell脚本中的循环?

ltqd579y  于 2021-06-25  发布在  Hive
关注(0)|答案(1)|浏览(458)
date=20190901

  hql="select DISTINCT content from ods_tblog_content where dt==$dt"

  hive -e "$hql"> data/"content_$dt"

这个脚本按特定日期获取数据,其中我将日期指定为“2019年9月1日”。如何使用循环获取每个月特定日期的内容?即:

20190901
20190801
20190701
20190620
20190515

我觉得我应该把这些日期放到一个数组中,然后用一个循环来完成?我不熟悉shell脚本。

inb24sb2

inb24sb21#

你的想法是对的。下面是一个脚本来帮助您理解语法。


# !/bin/sh

hql="select DISTINCT content from ods_tblog_content where dt=${dt}"

# Array for desired dates

dates=(20190901 20190801 20190701 20190620 20190515)
for dt in ${dates[@]}
do 
hive -e "$hql" > /data/"content_${dt}"
done

相关问题