sed magic: a simple guide

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, a great sed introduction.

Have fun!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s