Created
October 5, 2017 12:47
-
-
Save rsiddle/7244c769a1b7f3284563013f47b89178 to your computer and use it in GitHub Desktop.
A short script that can escape or unescape a list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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