De-obfuscation of CSS

Here is a little command line fu I worked today, it seemed post worthy.

I found a site I wanted to emulate so I checked out the CSS file only to see a “obfuscated” version, missing new lines and spaces.  I whipped up this little sequence of sed commands to de-obfuscate the CSS.

cat site.css |sed “s|}|}\n|g”|sed “s|;|;\n|g”|sed “s|{|{\n|g”|sed “s|^\([^}]\)|  \1|g”|sed “s|^ *\([^{]*\){|\1{|g” > out.css

List each line of the CSS file, add a new line after all }, { and ; characters.  Add 2 spaces to all lines, then remove the spaces from lines that have a { at the end.  This results in some pretty readable code.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

WordPress Themes