gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:12:04 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com