2015-08-28 119 views
0

我已經制作了一個能夠完成我所要做的90%的腳本。它進入一個目錄(根據輸入的日期),它改變我送入數組的文件。但是,我想將此腳本更改爲還包含日期數組(這是目錄名稱)。它將在目錄中循環,當它從文件名數組中找到一個文件時,它會糾正它並繼續前進,直到所有文件都得到糾正。我已經嘗試了幾個不同的版本,但我不確定如何在文件更正後如何實現第二個數組以繼續查看目錄。如何使用shell腳本查看目錄和更改文件?

目前,我的劇本是這樣的:

debug=false 

## *****Put file name in quotes****** 
declare -a arr=("UF19905217" "UG19905218") 

##Put date in DDMMYYYY format for the date the message was original processed. 
DATE="25082015" 

## now loop through the above array 
for i in "${arr[@]}" 
do 
    #if "$debug; then 
     echo "Fix file named: Inbound_$i.msg" 
     MSG="Inbound_$i.msg" 
    #fi 

    if [ ! -d "$MSG" ]; then 
    # Enter what you would like changed here. You can copy and paste this command for multiple changes 

     #DATATYPE 
     printf "%s\n" ',s/<DataType>EDI<\/DataType>/<DataType>830<\/DataType>/g' wq | ed -s /data1/Inbound/$DATE/$MSG   

     echo "Complete" 
    else 
      echo "Message not found or errored!" 
    fi 

done 

我感謝所有幫助您可以提供。謝謝。

+1

沒見過'ed'。尼斯。 – chepner

回答

1

我相信你只是想附上你有循環的一個循環,在希望的目錄遍歷:在使用了一段時間

debug=false 

## *****Put file name in quotes****** 
declare -a arr=("UF19905217" "UG19905218") 

##Put date in DDMMYYYY format for the date the message was original processed. 
dates=(25082015 26082015) 

for DATE in "${dates[@]}"; do  
    for i in "${arr[@]}"; do 
    MSG="Inbound_$i.msg" 
    if $debug; then 
     echo "Fix file named: $MSG" 
    fi 

    if [ ! -d "$MSG" ]; then 
     printf "%s\n" ',s/<DataType>EDI<\/DataType>/<DataType>830<\/DataType>/g' wq | ed -s /data1/Inbound/$DATE/$MSG 
     echo "Complete" 
    else 
     echo "Message not found or errored!" 
    fi 
    done 
done 
+0

這個伎倆。謝謝! – FrankCapone

相關問題