Skip to content

Instantly share code, notes, and snippets.

@JiggyPete
Created March 31, 2022 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JiggyPete/b4c722446c67e990e0e0ad4a4fe2116d to your computer and use it in GitHub Desktop.
Save JiggyPete/b4c722446c67e990e0e0ad4a4fe2116d to your computer and use it in GitHub Desktop.
def escape(text)
text.gsub('"', '\"')
end
search_term = escape(ARGV[0])
replace_term = escape(ARGV[1])
piped_input = STDIN.entries
piped_input.each do |line|
parts = line.split(":")
filename = parts[0]
line_number = parts[1]
puts "filename: #{filename}"
puts `sed -i '' -e "#{line_number}s/#{search_term}/#{replace_term}/g" #{filename}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment