当`unzip -l`时,从zip压缩文件中提取文件名列表. [英] Extract list of file names in a zip archive when `unzip -l`
本文介绍了当`unzip -l`时,从zip压缩文件中提取文件名列表.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我做unzip -l zipfilename
时,我看到
1295627 08-22-11 07:10 A.pdf
473980 08-22-11 07:10 B.pdf
...
我只想查看文件名.我试试这个
I only want to see the filenames. I try this
unzip -l zipFilename | cut -f4 -d" "
但是我不认为分隔符只是" "
.
but I don't think the delimiter is just " "
.
推荐答案
假定所有文件名中都没有空格:
Assuming none of the files have spaces in names:
unzip -l filename.zip | awk '{print $NF}'
我的解压缩输出同时具有页眉和页脚,因此awk脚本变为:
My unzip output has both a header and footer, so the awk script becomes:
unzip -l filename.zip | awk '/-----/ {p = ++p % 2; next} p {print $NF}'
处理带空格的文件名的版本:
A version that handles filenames with spaces:
unzip -l filename.zip | awk '
/----/ {p = ++p % 2; next}
$NF == "Name" {pos = index($0,"Name")}
p {print substr($0,pos)}
'
这篇关于当`unzip -l`时,从zip压缩文件中提取文件名列表.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文