Environment
Situation
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.
Resolution
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: &)
:%s/&//g
To replace a string with another string: (example: billy for bob)
:%s/billy/bob/g
To delete a line which contains a specific string (example: mickeymouse):
:g/mickeymouse/d
:%s:\(<dn>[^,]*\),.*:\1,OU=printers,O=novell</dn>:g
- 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
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=192.168.123.55 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
cat padbtxt.xml |sed '/<acl>/,/<\/acl>/d'| sed '$!N; /^\(.*\)\n\1$/!P; D'>output.xml