Skip to content

Instantly share code, notes, and snippets.

@IceDragon200
Last active August 29, 2015 14:23
Show Gist options
  • Save IceDragon200/17999d51f1b34294846e to your computer and use it in GitHub Desktop.
Save IceDragon200/17999d51f1b34294846e to your computer and use it in GitHub Desktop.
result = []
last_line = nil
File.open('my_awesome_file_of_doom_and_cookies.txt', 'r') do |file|
file.each_line do |line|
if line =~ /expected_line/ && (last_line && last_line =~ /expected_previous_line/)
result.pop
end
result << line
last_line = line
end
end
File.write('my_awesome_file_of_doom2.txt', result.join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment