2016-10-03 7 views
2

FILELIST拡張子を持つディレクトリ内のすべてのファイルを繰り返し処理しようとしています。しかし、私はこれらのファイルの内容を読みたいと思います。他のファイルのパスとファイル名を含んでいます。これらのファイルは、私は別の場所に移動したいと思います。私がこれまで持って何Linuxシェル:複数のファイルリストを繰り返し、ファイル内の各行でアクションを実行する方法は?

FileA.FILELIST 
/somepath/File1.csv 
/somepath/File2.csv 
FileB.FILELIST 
/somepath/File3.csv 
/somepath/File4.csv 

...事前に

#!/bin/bash 
# Iterate all file lists 
for fl in /path/Inbox/*.FILELIST 
do 
    #Iterate the content of the current file list 
    while read line; 
    do 
    #Move it to the Archive directory... 
    done < $fl 
done 

感謝!!

+1

'#Move ...'行を 'mv" $ line "/ archive/dir"に置き換えてください。 – anubhava

答えて

1

これを試してみてください。..

ls *.FILELIST|while read file # Reading all files named ".FILELIST" - 1 by 1. 
do 
    echo "File is $file" # Your current file in the list 

    cat $file|while read line # Now reading the lines of the file 
    do 
     echo "Line is $line" 
    done 
done 

提供された入力用のサンプル出力を。

>Wed Oct 05|01:54:14|[email protected][STATION]:/root/ga/scripts/temp/tmp % ls -lrtha *.FILELIST 
-rw-rw-r--. 1 gaurav gaurav 40 Oct 5 01:52 FileA.FILELIST 
-rw-rw-r--. 1 gaurav gaurav 40 Oct 5 01:52 FileB.FILELIST 
>Wed Oct 05|01:54:18|[email protected][STATION]:/root/ga/scripts/temp/tmp % cat *.FILELIST 
/somepath/File1.csv 
/somepath/File2.csv 
/somepath/File1.csv 
/somepath/File2.csv 
>Wed Oct 05|01:54:23|[email protected][STATION]:/root/ga/scripts/temp/tmp % ./a.sh 
File is FileA.FILELIST 
Line is /somepath/File1.csv 
Line is /somepath/File2.csv 
File is FileB.FILELIST 
Line is /somepath/File1.csv 
Line is /somepath/File2.csv 
>Wed Oct 05|01:54:26|[email protected][STATION]:/root/ga/scripts/temp/tmp % 
1

あなたのスクリプトはよく見えますが、以下のようないくつかの微調整で、あなたのために仕事をする必要があります。私はreadの条件を追加して、あなたが読んでいるファイルで利用可能ならば特殊文字を扱います。

#/bin/bash 

for file in /path/Inbox/*.FILELIST 
do 
    while IFS= read -r -d '' line; 
    do 
     echo "$line" 

     # mv "$line" "$targetPath" 
     # Do whatever else you want to do with the line here 

    done < "$file" 
done 
関連する問題