Skip to content

Instantly share code, notes, and snippets.

@rsiddle
Created October 5, 2017 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsiddle/7244c769a1b7f3284563013f47b89178 to your computer and use it in GitHub Desktop.
Save rsiddle/7244c769a1b7f3284563013f47b89178 to your computer and use it in GitHub Desktop.
A short script that can escape or unescape a list.
#!/usr/bin/env ruby
require 'cgi'
CGI_METHODS = %w[escape unescape]
USAGE = "usage: #{File.basename(__FILE__)} input output type"
input = ARGV[0]
output = ARGV[1]
type = ARGV[2]
if !output || !input ||!File.exist?(input) || !CGI_METHODS.include?(type)
$stderr.puts USAGE
exit(1)
end
begin
File.open(output, 'w') do |file|
IO.readlines(input).each do |line|
file.puts(CGI.send(type, line))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment