我正在尝试迭代目录中具有 FILELIST 扩展名的所有文件,我设法做到了。但后来我想读取这些文件的内容,其中包含其他文件的路径和文件名。我想将这些文件移动到另一个位置。
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
提前致谢!!
最佳答案
试试这个..
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|gaurav@[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|gaurav@[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|gaurav@[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|gaurav@[STATION]:/root/ga/scripts/temp/tmp %
关于Linux shell : how to Iterate multiple file lists and take action on each line in the file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39826423/