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
I will use the final desired out 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
Tested on 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.properties
Update: successfully testest on Solaris
SunOS fakename 5.11 11.4.63.157.1 i86pc i386 i86pc non-global-zone