解凍せずにzipから特定のファイル名を抽出します。

解凍せずにzipから特定のファイル名を抽出します。

次のように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

ベストアンサー1

やや複雑な仕様です。私が正しく理解した場合は、パスに含まれていないアーカイブメンバーのリストが必要ですdeployfiles(大文字と小文字を区別しない限りdev)、同じ基本名を持つ後続のファイルを無視する必要があります。

だから:

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

zipinfo -l存在するzipアーカイブメンバーパスのリストのみを取得する方法の1つ

おすすめ記事