Skip to content

Instantly share code, notes, and snippets.

@audy
Created July 29, 2014 14:36
Show Gist options
  • Select an option

  • Save audy/71091381755fba5bd4f0 to your computer and use it in GitHub Desktop.

Select an option

Save audy/71091381755fba5bd4f0 to your computer and use it in GitHub Desktop.
find replace strings in a text file given a CSV of: target,replacement
#!/usr/bin/env ruby
require 'csv'
translation = CSV.read(ARGV[0])
translation.map! { |x| [/#{x[0]}/, x[1]] }
d = File.read('/dev/stdin')
translation.each do |target, replacement|
d.gsub! target, replacement
end
print d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment