Shell 遍歷文件夾中所有文件並進行相關操作


遍歷文件夾中所有文件,獲取文件名,並對指定文件做相應操作

#!/bin/bash

dir=$(ls -l /usr/ |awk '/^d/ {print $NF}')

for file in $dir
do

if [[ $(echo $file | grep "AQSS") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQSS/$1/
elif [[ $(echo $file | grep "AQCS") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQCS/$1/
elif [[ $(echo $file | grep "AQKJ") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQKJ/$1/
elif [[ $(echo $file | grep "AQMC") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQMC/$1/
elif [[ $(echo $file | grep "AQKC") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQKC/$1/
elif [[ $(echo $file | grep "AQFZ") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQFZ/$1/ 
elif [[ $(echo $file | grep "AQGX") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQGX/$1/
elif [[ $(echo $file | grep "AQDQ") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQDQ/$1/
elif [[ $(echo $file | grep "AQLJ") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQLJ/$1/
elif [[ $(echo $file | grep "AQMT") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQMT/$1/
elif [[ $(echo $file | grep "AQBJ") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQBJ/$1/
elif [[ $(echo $file | grep "AQKY") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQKY/$1/
elif [[ $(echo $file | grep "AQYC") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQYC/$1/
elif [[ $(echo $file | grep "AQKD") != "" ]] then
  hdfs dfs -put $file /origin_data/aqjc/log/topic_AQKD/$1
  else 
  echo $file
fi
done

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM