Skip to content

Instantly share code, notes, and snippets.

@meetme2meat
Created July 29, 2016 06:56
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 meetme2meat/14a4f95e1110b962ac06eae4df6b58b0 to your computer and use it in GitHub Desktop.
Save meetme2meat/14a4f95e1110b962ac06eae4df6b58b0 to your computer and use it in GitHub Desktop.
Test-2 file
require 'rubygems'
$zone = "-06:00"
require 'pry'
#inspect.txt
#rinspect.txt
MONTH= {"Jan" => 1,"Feb" =>2,"Mar" => 3,"Apr" => 4,"May" => 5,"Jun" => 6,"Jul" => 7,"Aug" => 8,"Sep" => 9,"Oct" => 10,"Nov" => 11,"Dec" => 12}.freeze
def find_time(time)
day = time.match(/^\d{2}/)[0].to_i
month = MONTH[time.match(/[A-Z][a-z]{2}/)[0]]
year = time.match(/\d{4}/)[0].to_i
hour,min,sec = time.scan(/(\d{2}):(\d{2}):(\d{2})/)[0].collect(&:to_i)
Time.new(year,month,day,hour,min,sec,$zone)
end
def extract_time(data)
time = data.match(/\d{2} Jul 2016 \d{2}:\d{2}:\d{2}/)[0]
find_time(time)
end
message_ids = []
lineno =[]
data = File.open("#{Dir.pwd}/failed.txt",'r') do |i|
while(!i.eof?)
text= i.readline
message_ids << text.scan(/\w{10}/)[0]
#message_ids = data.scan(/\w{10}/)
lineno << text.match(/(\d\d+)/)[1]
end
end
exit if lineno.count != message_ids.count
lineno.each_with_index do |i,index|
print "\r at #{index+1} "
output = `grep -r #{i} #{Dir.pwd}/failed.txt | grep #{message_ids[index]}`
puts output
end
lineno.each_with_index do |i,index|
print "\r at #{index+1} "
output = `grep -r #{i} #{Dir.pwd}/failed.txt | grep #{message_ids[index]}`
if output != ""
text = `sed -n '#{i.to_i+1},#{i.to_i+1}p' #{Dir.pwd}/inspect.txt`
punch_time = extract_time(text)
message_id = text.match(/\w{10}/)[0]
binding.pry if message_id != message_ids[index]
other_grep = "grep #{message_id} #{Dir.pwd}/rinspect.txt"
outputr = `#{other_grep}`.split('\n')
all_times = outputr.map { |s| extract_time(s)}
min = all_times.map { |i| (i-punch_time) }
puts "#{message_id} #{punch_time.to_s} -- #{min.inspect}"
else
puts ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment