LinuxShell:如何迭代多个文件列表并对文件中的每一行执行操作?

LinuxShell:如何迭代多个文件列表并对文件中的每一行执行操作?,linux,list,shell,file,loops,Linux,List,Shell,File,Loops,我正在尝试迭代一个目录中具有文件列表扩展名的所有文件,我成功地做到了这一点。但是我想阅读这些文件的内容,包括其他文件的路径和文件名。这些文件,我想移动到另一个位置 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

我正在尝试迭代一个目录中具有文件列表扩展名的所有文件,我成功地做到了这一点。但是我想阅读这些文件的内容,包括其他文件的路径和文件名。这些文件,我想移动到另一个位置

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
#/bin/bash
#迭代所有文件列表
对于fl in/path/Inbox/*.FILELIST
做
#迭代当前文件列表的内容
读行时;
做
#将其移动到存档目录。。。
已完成<$fl
完成

提前谢谢

您的脚本看起来不错,通过下面的一些调整,应该可以完成这项工作。我在
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
#/bin/bash
对于/path/Inbox/*.FILELIST中的文件
做
而IFS=read-r-d''行;
做
回音“$line”
#mv“$line”“$targetPath”
#你想用这条线做什么都行
完成<“$file”
完成
试试这个

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 %
只需将
#Move…
行替换为
mv“$line”/archive/dir