[英]Zcat multiple compressed files in a for loop
Im fairly new to bash scripting and i've been searching here in stackoverflow for an answer that will match what im looking for but cant find an exact match.. apologies if this has already been answered. 我是bash脚本的新手,我一直在这里在stackoverflow中寻找一个答案,该答案将与我在寻找的内容相匹配,但找不到确切的匹配结果。
I have multiple folders that has multiple compressed files, some are gzip extension , some doesnt have extension. 我有多个包含多个压缩文件的文件夹,有些是gzip扩展名,有些没有扩展名。
The only way Ive been able to see the content of the compressed file is by doing 我能够查看压缩文件内容的唯一方法是
zcat filename.gzip > filename
My goal is to create a for loop that will : 我的目标是创建一个for循环,该循环将:
Thank you! 谢谢!
To decompress all files that gzip
would handle using find
, basename
and a while
loop: 要使用
find
, basename
和while
循环解压缩gzip
将处理的所有文件:
find . -type f | while read f; do
set -e # You should probably always script with set -e
# This will cause the subshell to stop on errors.
zcat < "$f" > "$f-new" || continue
rm "$f"
done
This should also handle any weird quoting that comes up. 这也应该处理出现的任何奇怪的报价。 The
while
loop will run in a subshell, and set -e
will set the stop on error option in it so that if there's an error with either the zcat
or the rm
it won't keep plowing ahead destroying everything in sight. while
循环将在子外壳中运行,并且set -e
将在其中设置错误停止选项,这样,如果zcat
或rm
出现错误,它就不会继续努力破坏所有可见的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.