Shell脚本 - 从Hive表获取数据到文本文件

时间:2015-04-08 00:20:23

标签: shell hadoop hive

我正在修改一个shell脚本,而且我不熟悉脚本。

我能够从hive表中提取数据并输入txt文件,但是数据从我已经预先输入了列标题的第一行开始。

如何从第二行开始加载数据?

temp_pull()
{
hadoop fs -cat /user/hive/warehouse/test_database.db/$1/* >> $2
}

temp_pull hive_table sample_txt_file.txt

示例.txt文件:

col1    col2    col3
调用temp_pull()之后

col1    col2    col3    hivedataRow1    hivedataRow1    hivedataRow1
hivedataRow2    hivedataRow2    hivedataRow3   

1 个答案:

答案 0 :(得分:0)

试试这个。

 temp_pull()
  {
  hadoop fs -cat /user/hive/warehouse/test_database.db/$1/*  | tail -n +2 >> $2
  }

  temp_pull srclist sample_txt_file.txt

其他解决方案。

 temp_pull()
 {
   hive -e 'select * from '$1'' | tail -n +2  > $2
  }

  temp_pull stud_02 sample_txt_file1.txt

根据您的需要进行调整。