列出 zip 文件的内容如下:
wladmin@solarishost:/tmp$ unzip -l -q /tmp/package-391.zip | awk '{ print $4 }' | sed -n '3,$p' | grep -v '^$'
myapp/src/stage/bras.war
myapp-configuration/src/config/dev/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties
myapp-configuration/src/config/perf/deployfiles/acid.properties
myapp-configuration/src/config/prod/deployfiles/acid.properties
myapp-configuration/src/config/qa/deployfiles/acid.properties
myapp-configuration/src/config/uat/deployfiles/acid.properties
从上面我希望通过获取所有具有
deployfile
而没有 DEV
的文件名来创建删除文件列表,我可以使用下面的方法来做到这一点。
wladmin@solarishost:/tmp$ unzip -l -q /tmp/package-391.zip | awk '{ print $4 }' | sed -n '3,$p' | grep -v '^$' | grep deployfiles | grep -v -i DEV
myapp-configuration/src/config/perf/deployfiles/acid.properties
myapp-configuration/src/config/prod/deployfiles/acid.properties
myapp-configuration/src/config/qa/deployfiles/acid.properties
myapp-configuration/src/config/uat/deployfiles/acid.properties
从剩下的任何东西中,即
myapp/src/stage/bras.war
myapp-configuration/src/config/dev/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties
从剩余的输出中,我希望获得出现多次的文件名,即
myapp-configuration/src/config/dev/bras.war
并将其添加到删除文件列表中
最终期望的输出:
myapp-configuration/src/config/perf/deployfiles/acid.properties
myapp-configuration/src/config/prod/deployfiles/acid.properties
myapp-configuration/src/config/qa/deployfiles/acid.properties
myapp-configuration/src/config/uat/deployfiles/acid.properties
myapp-configuration/src/config/dev/bras.war
我将使用最终所需的输出列表从 zip 中删除这些文件,并仅使用以下 2 个文件重建 zip
myapp/src/stage/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties
请推荐。
wladmin@solarishost:/tmp$ uname -a
SunOS solarishost 5.11 11.4.62.151.3 sun4v sparc sun4v non-global-zone
在 Linux 上测试
$ zip -d package-391.zip $(
awk -F/ '
(!/\/$/ && /deployfile/ && !/[dD][eE][vV]/) || (!/\/$/ && seen[$NF]++){
printf "%s ", $0
}
' <(unzip -Z1 package-391.zip)
)
deleting: myapp-configuration/src/config/dev/bras.war
deleting: myapp-configuration/src/config/perf/deployfiles/acid.properties
deleting: myapp-configuration/src/config/prod/deployfiles/acid.properties
deleting: myapp-configuration/src/config/qa/deployfiles/acid.properties
deleting: myapp-configuration/src/config/uat/deployfiles/acid.properties1