Linux shell : how to Iterate multiple file lists and take action on each line in the file?

标签 linux list shell file loops

我正在尝试迭代目录中具有 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/

相关文章:

javascript - 如何在 Javascript 前端使用 Firebase Firestore .push() 方法

linux - 使用 Linux 命令 head 和 tail

c - 使用 readline 防止回车输出

linux - Bash 脚本忽略 if, then 语句;每次返回相同的结果

Git:列出 git 分支,按(并显示)日期排序

javascript - 正则表达式替换列表中的 0 但不是 10、20、30 等中的 0 - 使用 js 替换

linux - 如何删除名称以 "--"开头的文件?

linux - 从 bash shell 编辑 XML 文件

linux - 在结构列表上调用 std::sort 时将 const 作为 'this' 参数错误传递

android - Cordova构建android失败