Python Forum
time difference bettwenn logs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time difference bettwenn logs
#3
Personally, I would not use regex in situations where the position of the data is known and unchanging; rather, I'd simply use the index positions.

As a simple demonstration:

with open("log", mode="r", encoding="UTF-8") as log:
    for entry, item in enumerate(log, 1):
        time_stamp = item[12:20]
        print(f"{entry:02d}:~", time_stamp)
To add: as working demonstration of the difference between the time entries:

from datetime import datetime

time_stack = []

with open("log", mode="r", encoding="UTF-8") as log:
    for entry, item in enumerate(log, 1):
        time_str = item[12:20]
        time_stamp = datetime.strptime(time_str, '%H:%M:%S')
        time_stack.append(time_stamp)
        if len(time_stack) > 1:
            print(f"{entry:02d}:~", time_str, (time_stack[1] - time_stack[0]))
            time_stack.pop(0)
        else:
            print(f"{entry:02d}:~ Start", time_str)
Output:
01:~ Start 07:38:33 02:~ 07:38:33 0:00:00 03:~ 07:38:33 0:00:00 04:~ 07:38:33 0:00:00 05:~ 07:38:33 0:00:00 06:~ 07:38:33 0:00:00 07:~ 07:38:33 0:00:00 08:~ 07:38:33 0:00:00 09:~ 07:38:33 0:00:00 10:~ 07:38:33 0:00:00 11:~ 07:38:33 0:00:00 12:~ 07:38:33 0:00:00 13:~ 07:38:34 0:00:01 14:~ 07:38:34 0:00:00 15:~ 07:38:35 0:00:01 16:~ 07:38:37 0:00:02
enkliy and snippsat like this post
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
time difference bettwenn logs - by enkliy - Nov-20-2023, 09:25 AM
RE: time difference bettwenn logs - by snippsat - Nov-20-2023, 10:32 AM
RE: time difference bettwenn logs - by rob101 - Nov-20-2023, 11:33 AM
RE: time difference bettwenn logs - by enkliy - Nov-20-2023, 01:18 PM
RE: time difference bettwenn logs - by deanhystad - Nov-20-2023, 08:43 PM
RE: time difference bettwenn logs - by Larz60+ - Nov-21-2023, 10:32 AM
RE: time difference bettwenn logs - by Pedroski55 - Nov-21-2023, 11:04 AM
RE: time difference bettwenn logs - by enkliy - Nov-21-2023, 02:05 PM
RE: time difference bettwenn logs - by rob101 - Nov-21-2023, 02:26 PM
RE: time difference bettwenn logs - by enkliy - Nov-21-2023, 02:41 PM
RE: time difference bettwenn logs - by rob101 - Nov-21-2023, 03:00 PM
RE: time difference bettwenn logs - by enkliy - Nov-21-2023, 03:36 PM
RE: time difference bettwenn logs - by rob101 - Nov-21-2023, 03:39 PM
RE: time difference bettwenn logs - by deanhystad - Nov-21-2023, 04:43 PM
RE: time difference bettwenn logs - by rob101 - Nov-21-2023, 04:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Hard time trying to figure out the difference between two strings carecavoador 2 755 Aug-16-2023, 04:53 PM
Last Post: carecavoador
  Sum up Time difference tester_V 10 2,848 Apr-06-2023, 06:54 AM
Last Post: Gribouillis
  Bot refuses to count logs. M1racle 0 1,306 Dec-13-2021, 06:42 PM
Last Post: M1racle
  Get Azure activity logs using python script raham3406 4 3,681 Apr-27-2021, 05:10 AM
Last Post: raham3406
  How to get indices of minimum time difference Mekala 1 2,229 Nov-10-2020, 11:09 PM
Last Post: deanhystad
  How to calculate time difference between each row of dataframe in seconds Mekala 1 2,667 Jul-16-2020, 12:57 PM
Last Post: Larz60+
  python realtime parsing logs anna 2 2,972 Jul-05-2020, 06:36 AM
Last Post: anna
  capture logs on specific port anna 1 1,818 Jun-27-2019, 03:47 PM
Last Post: Larz60+
  Correlation of Incidents using time difference Rajhesh 1 1,894 Jun-27-2019, 03:44 PM
Last Post: Larz60+
  Time Difference in Epoch Microseconds then convert to human readable firesh 4 11,756 Feb-27-2018, 09:08 AM
Last Post: firesh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020