Created
September 24, 2021 10:02
-
-
Save dorianmariecom/a5d67f17408470045346c7708209fa7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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