背景:
需要批量把hdfs上某个目录中的所有以.pending 结尾的文件,去掉.pending后缀。主要原因是建立的hive外表无法读取.tmp或.pending的文件,所以需要去掉后缀。
hdfs上文件的结构是根目录/data/test/flink/ttengine_predict/下有dt=2017-12-28的天级目录,在天级目录下会有hour=00-23的24个小时级目录,文件都在小时级目录中。
#!/bin/bash  
#print the directory and file
hadoop fs -ls /data/abc/flink/ttengine_predict/dt=2017-12-27/ | awk '{print $8}' > files0.txt
#循环遍历,提取所需数据
cat  ./files0.txt | while read line
do
  echo "$line"
  hadoop fs -ls $line | awk '{print $8}' > files1.txt
  cat  ./files1.txt | while read fname
  do
    echo "$fname"
    _path=`echo $fname | awk -F'.' '{print $1}'`
    hadoop fs -mv $fname $_path
    #echo $_path
  done
done
                










