Skip to content

Instantly share code, notes, and snippets.

@dorianmariecom
Created September 24, 2021 10:02
Show Gist options
  • Save dorianmariecom/a5d67f17408470045346c7708209fa7a to your computer and use it in GitHub Desktop.
Save dorianmariecom/a5d67f17408470045346c7708209fa7a to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
if ARGV.size < 2
puts "USAGE: ruby-replace FROM TO FILES..."
puts
puts "ALTERNATIVE:"
puts "ls | ruby-replace FROM TO"
exit
end
from = ARGV[0]
to = ARGV[1]
files = ARGV[2..-1].any? ? ARGV[2..-1] : STDIN.each_line.to_a.map(&:strip)
files.each do |file|
next if File.directory?(file)
File.write(file, File.read(file).gsub(from, to))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment