Friday, August 28, 2009

Get mac address from xml and generate computer names for each mac

Parsing xml is pretty easy using grep. The benefit of sed/grep is that they are right there -- if you have cygwin, Linux or Mac.

Here is an example format:



<macs>

<string>00-00-00-00-00-01</string>
<string>00-00-00-00-00-02</string>
</macs>


This will parse the xml file formatted like above and generate a computer name for each mac address. A good application of sed/grep/bash. If you are installing a lot of new computers and need to associate new names with mac addresses, this is a good start.


grep All\ Computers.plist | sed -e 's/<\/*string>//g' | while read line; do ((i++)); echo "pc-$i $line"; done > macs.txt

No comments:

Post a Comment