Showing posts with label sed. Show all posts
Showing posts with label sed. Show all posts

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

Monday, June 1, 2009

Inserting a blank line with sed

#I found this to be a bit tricky

sed -e '/pattern/i\
\ # <-- this is the key
' input_file > output_file

Friday, May 29, 2009

Removing carriage returns with sed

sed -e s/$'\r'/\ /g input_file # remove carriage returns

sed -e 's/\n/ /g' input_file # remove newlines

Insert text before a pattern with sed

cat some_file | sed '/pattern/i\
text to insert
' > output_file