Nicolás Brailovsky


A modern blog

sed magic: a simple guide

author Posted by: nico on date Sep 24th, 2009 | filed Filed under: Console, Programming
The other day I had to create one of those “enum to string” functions. They really suck, always getting out of sync, so I made a script to auto-update the header file containing this function… just add a target to the makefile and you’re done! 11Sed

Anyway, this is the part of the script I came up with to get the enum elements:


cat enum_definition.h | sed -n ‘/enum OID/,/\}\;/ s/\(.*\)/\1/p’

Nice voodoo, isn’t it? How the hell are you supposed to understand that? Well, you’re not, sed is write-only-code, but you can try reading http://www.grymoire.com/Unix/Sed.html#toc-uh-25, a great sed introduction.

Have fun!

     Add A Comment

trackback Trackback URI | rsscomment Comments RSS