Skip to content

Latest commit

 

History

History
97 lines (57 loc) · 2.46 KB

README.pod

File metadata and controls

97 lines (57 loc) · 2.46 KB

NAME

zipupdate - Update .zip archives in-place

SYNOPSIS

zipupdate.pl [--match "\.xml"] --command <filter> *.zip

DESCRIPTION

This program acts on one or more .zip archives. For each contained file whose name matches a given pattern, the file content is filtered by an external command and written back to the .zip archive.

ARGUMENTS

-h, --help

Print program help and exit

-v, --verbose

Print output about every performed operation.

-c, --command filter-command

Command line with arguments to filter files through. The command is expected to accept input on stdin and write output to stdout. The command is interpreted by a shell and may contain pipes etc.

-m, --match regex

Optional argument: A regular expression that describes which inner files of the .zip archives to modify. It is matched against full file names and paths of the contained files. The forward slash "/" is used as directory delimiter. If not given, all files are matched.

EXAMPLES

How to update .zip files full of .xml files

Assume you have a number zip archives that contain a tree of XML files and you want to make systematic changes in all of them.

xmlstarlet is a command line tool to alter XML files and is well suited to add attributes, rename elements etc based on XPath expressions.

Adding an attribute to a certain element
find . -name "*.zip" -print0 | xargs -0 zipupdate.pl \
  --match "directoryname/.*\.xml" --command \
  "xmlstarlet edit -P -S --insert //MatchingElement --type attr --name newattribute --value value"
Removing an attribute from all nodes
find . -name "*.zip" -print0 | xargs -0 zipupdate.pl \
  --match "\.xml" --command "xmlstarlet edit -P -S --delete //@version"
Adding a new child element
find . -name "*.zip" -print0 | xargs -0 zipupdate.pl \
  --match "\.xml" --command \
  "xmlstarlet edit -P -S --subnode /RootElement/MainElement --type elem --name DetailElement --value ''"

Encoding conversion

Converting XML files

The command is interpreted by a shell and you can use pipes:

find . -name "*.zip" -print0 | xargs -0 zipupdate.pl \
  --match "\.xml" --command \
  'recode iso-8859-1..utf8 | sed -e "s/\(<?xml version=\"1.0\" encoding=\"\)iso-8859-1\(\"?>\)/\1utf-8\2/"'

SEE ALSO

http://xmlstar.sourceforge.net/

XMLStarlet Command Line XML Toolkit