Gl.ib.ly

(glibly); Just another techie blog.

Creating an HTML file with white space traces

Posted by Tariq • Tuesday, December 9. 2008 • Category: One liners
Once upon a time I was comparing some Java files. Now one way to find plagiarism among students who share program code is to look at the white space traces in a file. Students typically try and edit the source code: changing variable names and function names; however, they usually fail to conceal the original author's white space patterns. White space consists of characters which don't appear on screen such as spaces, tabs, and new line characters. Anyway you can catch lots of cheaters by looking at the white space patterns in files ... maybe that's another blog entry, so back to this one.



Today I am making html files for each code file (java in this example) in a directory and highlighting the white space in that file in pretty colours. We will highlight space, tabs, and new lines. Here is a one liner to do that:
for file in $(ls *.java); do echo "&lt;html&gt;&lt;head&gt;&lt;title&gt;"$file" Source&lt;/title&gt;&lt;style&gt;body { font-family: courier; background: #EEE;} .tab{ background: #F00; }.space{ background: #0F0; } .eol{ background: #00F; }&lt;/style&gt;&lt;/head&gt;&lt;body&gt;" > $file.html; cat $file | sed "s/</\&lt;/g"sed "s/>/\&gt;/g" | sed "s/ /\\<span class=\"space\"\>\&nbsp;\<\/span\>/g" | sed "s/\t/<span class=\"tab\"\>\&nbsp;\&nbsp;\&nbsp;\<\/span\>/g" | sed "s/$/\<span class=\"eol\"\>\&nbsp;\<\/span\><br \/\>/" >> $file.html; echo "</body></html>" >> $file.html; done


Cool! Results below and as you can see white space isn't as uniform as you might expect.

Defined tags for this entry: , , , ,
Vote for articles fresher than 90 days!
Bookmark Creating an HTML file with white space traces  at del.icio.us Digg Creating an HTML file with white space traces Bloglines Creating an HTML file with white space traces Technorati Creating an HTML file with white space traces Fark this: Creating an HTML file with white space traces Bookmark Creating an HTML file with white space traces  at YahooMyWeb Bookmark Creating an HTML file with white space traces  at Furl.net Bookmark Creating an HTML file with white space traces  at blogmarks Stumble It!

0 Trackbacks

  1. No Trackbacks

0 Comments

Display comments as (Linear | Threaded)
  1. No comments

Add Comment


Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.