Useful vi and sed commands to manipulate iPrint XML files

  • 7008290
  • 05-Apr-2011
  • 26-Apr-2012


Novell iPrint for Linux


When mass creating or updating the Print Manager database using the XML import process, there are times when the administrator would like to execute complex find and replace operations.  This TID lists vi and sed examples which can assist in manipulating iPrint XML files.  

See KB 7003077 for more information on how to import XML data to the Print Manager database.


Useful vi commands to manipulate iPrint XML files
The following vi commands can be effective at quickly changing a lot of information within the padbtxt.xml or other iPrint XML input file.  To use these commands, go into the Colon Mode by typing : while not in Editing Mode.

To replace a string with blank: (example: &amp)

To replace a string with another string: (example: billy for bob)

To delete a line which contains a specific string (example: mickeymouse):

Search for lines which start with <dn>, skip the CN entry, and write the new string.
    • Note 1: this command is useful when changing the contexts of each printer agent in one command.  Caution: the Print Manager context will change as well, so you may need to manually change that back.
    • Note 2: OU=printers,O=novell is the example context which will be inserted for each printer agent entry when using the above command.

Within vi, add the NULL value at the end of the gateway load string.
:%s:</gatewayloadstring>$:\ NULL</gatewayloadstring>:g

Useful sed commands to manipulate iPrint XML files.
The following sed commands can be used when not in vi, but rather when at a command prompt.  In these examples, the file being manipulated is padbtxt.xml and the new file to be written is output.xml.

Using sed, search for gateway load commands in an XML and replace with a different gateway command:
sed -e s:iprintgw\ [=\ .0-9A-Z]*\</gatewayloadstring\>:'iprintgw PORT=LPR HOSTADDRESS= PRINTERNAME=PASSTHROUGH</gatewayloadstring>':g padbtxt.xml >output.xml

Using sed, add the NULL value to a gateway load string:
sed -e s:\</gatewayloadstring\>$:\ NULL\</gatewayloadstring\>:g padbtxt.xml > output.xml

Remove all the print driver entries from the XML:
cat padbtxt.xml |sed '/<driver>/,/<\/driver>/d'| sed '$!N; /^\(.*\)\n\1$/!P; D'>output.xml

Remove redirected/deleted printer entries from the XML:
cat padbtxt.xml |sed '/<redirectedprinter>/,/<\/redirectedprinter>/d'| sed '$!N; /^\(.*\)\n\1$/!P; D'>output.xml

Remove ACL entries from the XML:
cat padbtxt.xml |sed '/<acl>/,/<\/acl>/d'| sed '$!N; /^\(.*\)\n\1$/!P; D'>output.xml