Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created March 6, 2014 08:48
Show Gist options
  • Save yoggy/9385342 to your computer and use it in GitHub Desktop.
Save yoggy/9385342 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
#
# trim.rb - trim sensor & scenario log
#
def usage
puts <<-EOS
usage : ./trim_log.rb [start_time] [end_time] [file]"
example:
$ ./trim_log.rb 11:30 12:00 sensor_log.txt
$ ./trim_log.rb 13:00 15:45 scenario_log.txt
EOS
exit -1
end
def to_millis(str)
(h, m) = str.split(":").map {|s| s.to_i}
Time.new(2014, 3, 1, h, m, 0, "+09:00").to_i * 1000
end
usage if ARGV.size < 2
trim_st = to_millis(ARGV[0])
trim_et = to_millis(ARGV[1])
filename = ARGV[2]
f = open(filename);
while !f.eof
l = f.gets
ss = l.split(",")
t = ss[0].to_i
next if t < trim_st || trim_et <= t
puts l
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment