Skip to content

Instantly share code, notes, and snippets.

@Aenigma
Created May 27, 2014 06:49
Show Gist options
  • Save Aenigma/69c1ad49b5ec0a57cd81 to your computer and use it in GitHub Desktop.
Save Aenigma/69c1ad49b5ec0a57cd81 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
REGEX = %r{TRP.*(\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2}).*(\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2}).*(\d{2}:\d{2}:\d{2}).*(\d{4}\.\d{2}\.\d{2}\.\d{2}\.\d{2}\.\d{2})}
abort "You must enter file paths via CLI" unless ARGV.length > 0
ARGV.each do |file_path|
File.open(file_path, "rb") do |f|
results = f.read.scan(REGEX)
if results.length != 1
puts "File #{f.path} contained #{results.length} instances of pattern}"
next
end
puts results[0][2]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment