1. 程式人生 > >用shell命令獲得hdfs檔名並動態建立hive表

用shell命令獲得hdfs檔名並動態建立hive表

#獲得資料夾下的檔名並迴圈每個檔名

files=`hadoop fs -ls /home/out/aidfilter |  awk -F " " '{print $8}'`

for name in $files

do

#awk命令按“/”分割第五個

filename=`echo $name  | awk -F "/" '{print $5}'`

echo $filename

#執行hive指令碼 傳遞hive臨時變數

hive -f test.hql -hivevar tablename=$filename

done

test.hql語句如下要放在你執行本語句的同目錄下

create external table if not exists aid${tablename} (Id int,ChannelId int,ChannelName string,PlayDate string,MoniFlag4 string)row format delimited fields terminated by ',' location '/cm/tbl/aid${tablename}';