Skip to content

Instantly share code, notes, and snippets.

@moofkit
Created March 2, 2023 14:21
Show Gist options
  • Save moofkit/9a4ae6e3ad99e79bf2d43fc9e8447860 to your computer and use it in GitHub Desktop.
Save moofkit/9a4ae6e3ad99e79bf2d43fc9e8447860 to your computer and use it in GitHub Desktop.
Delete matched line from file
#!/usr/bin/env ruby
# frozen_string_literal: true
files = Dir.glob("app/jobs/**/*.rb")
puts "Found #{files.count} files"
files.each do |file|
content = File.read(file).split("\n")
content.each_with_index do |line, index|
if match = line.match(/Worker/)
puts "Found #{match[1]}Worker"
content.delete_at(index)
content.delete_at(index-1)
File.write(file, content.join("\n")+"\n")
break
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment