通过名称Shell脚本解压缩嵌套的.zip文件

诺佩娃

我正在下载一个具有非常深的嵌套结构的zip文件,我只需要从中选择一些文件即可。文件结构如下所示:

myfile.zip/
C*_01.zip, ....., C*_xx.zip/

在每个C * _xx.zip文件中:

a*.zip
b*.zip
..../
file1.txt
file2.txt
...
targetfile.txt
...

请注意,在每个“ C * .zip”上,我都需要选择目标文件。

我没有太多的shell脚本编写经验,因此我基于其他解决方案编写了一个脚本,但是它不起作用。我将不胜感激:

wget url | find . -name "myfile.zip" | while ["`find -type f -name 'C*.zip' | wc -l`" -gt 0 ]; do find -type f -name "b.zip" | find -type f -name "targetfile.txt" exec unzip -- '{}' \;; done
ging

创建一个类似的脚本文件fetchtarget.sh,并以URL作为第一个参数启动它。

#!/bin/sh

dir=$(mktemp -d)
cd $dir || exit

wget $1

# deep unzip loop
while true; do
   find -iname '*.zip' > zipindex
   test -s zipindex || break
   for zip in $(cat zipindex); do unzip -o $zip && rm $zip; done
done

# purge and show result
find $dir -name targetfile.txt -print -or -type f -exec rm {} \; 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章