Escaping HTML from the command line

If you want to escape HTML from the command line you can use the following one-liner:
  $ ruby -e "require 'cgi'; puts CGI.escapeHTML(STDIN.gets)"

To use this command, pipe it some HTML:
  $ echo "<p>Brilliant!</p>" | ruby -e "require 'cgi'; puts CGI.escapeHTML(STDIN.gets)"

If you find yourself using this command frequently your fingers will start screaming for relief. When this happens you might want to store the command as an alias. For CSH:
  $ alias htmlify 'ruby -e "require '\'cgi\' '; puts CGI.escapeHTML(STDIN.gets)"'

You can then escape your HTML more concisely:
$ echo "<p>Brilliant!</p>" | htmlify

|