gpt4 book ai didi

linux - 根据CSV输入选择并压缩文件

转载 作者:太空宇宙 更新时间:2023-11-04 11:21:25 25 4
gpt4 key购买 nike

我正在尝试读取 csv 文件中的每一列,然后使用 csv 上各列的数据搜索目录。读取所有行后,我想创建一个新目录,将文件复制到该目录,最后压缩该目录。关于如何做到这一点有什么想法吗?

这是 CSV 文件的示例:

add an example here...

最佳答案

这是根据您提供的信息编写的脚本草稿:

destdir="/path/to/destination/directory"
filelist=""
while IFS=, read col1 col2 col3 col4 ...
do
# check if the file should be included in filelist
if [ ... ]; then
filelist+="$col1/$col2/$col3.$col4 "
fi

if [ ! -z "$filelist" ]; then
mkdir -p $destdir
for goodfile in $filelist; do
cp $goodfile $destdir
done
fi
done < file.csv

为了让事情更清楚,我假设 CSV 文件中的列只是您感兴趣的文件的路径和名称的一部分。希望这可以帮助。 :)

关于linux - 根据CSV输入选择并压缩文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18016231/

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