0

Listing the contents of the zip file as below:

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

From the above I wish to create a delete file list by getting all filename that have deployfile and not having DEV which I'm able to do using the below.

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

from whatever is left i.e

myapp/src/stage/bras.war
myapp-configuration/src/config/dev/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties

From the leftover output, I wish to get any filenames that appear more than once i.e

myapp-configuration/src/config/dev/bras.war

and add it to the delete file list

Final desired output:

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

End goal is I will use the final desired output list to delete those files from the zip and reconstruct the zip with the below 2 files only:

myapp/src/stage/bras.war
myapp-configuration/src/config/dev/deployfiles/acid.properties

Kindly suggest.

wladmin@solarishost:/tmp$ uname -a

SunOS solarishost 5.11 11.4.62.151.3 sun4v sparc sun4v non-global-zone

Ashar
  • 491

1 Answers1

2

That's a bit of a convoluted specification. If I understand correctly, you want the list of archive members whose path does not contain deployfiles (unless they also contain dev case insensitively), and ignore subsequent files that have the same basename.

So:

zipinfo -1 file.zip | nawk -F/ '
  (! /deployfiles/ || tolower($0) ~ /dev/) && !seen[$NF]++'

zipinfo -l being one of the ways to get only the list of zip archive member paths.