Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created December 3, 2009 21:21
Show Gist options
  • Save seven1m/248536 to your computer and use it in GitHub Desktop.
Save seven1m/248536 to your computer and use it in GitHub Desktop.
dirty little script I used to fix escaped character sequences in a yaml file
lines = File.read(ARGV.first).split("\n")
File.open(ARGV.last, 'w') do |out|
lines.each do |line|
if line =~ /:/
key, value = line.split(/:\s*/, 2)
value = eval(value) if value =~ /^"/
if value =~ /\{|"|:/
value.gsub!(/"/, "\\\"")
value = "\"#{value}\""
end
out.write("#{key}: #{value}\n")
else
out.write("#{line}\n")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment