-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathserlog2log.py
More file actions
85 lines (66 loc) · 2.55 KB
/
Copy pathserlog2log.py
File metadata and controls
85 lines (66 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
'''
Copyright 2024 philippoo66
Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
def convert_file(input_file, output_file):
with open(input_file, 'r') as infile:
lines = infile.readlines()
output_lines = []
current_group = []
last_count = None
ts = 0
last_ts = 0
print(f"convering file {input_file} ...")
for line in lines:
# Entfernen von fuehrenden und nachfolgenden Leerzeichen und Zeilenumbruechen
line = line.strip()
# Wenn die Zeile leer ist, ueberspringen
if not line:
continue
# Zaehlen der Tabs in der Zeile
parts = line.split('\t')
parts_count = len(parts)
# Wenn die Anzahl der Tabs sich aendert, schreibe die vorherige Gruppe
if last_count and (parts_count != last_count):
dura = int(ts) - int(last_ts)
output_lines.append(f"{last_count-1}\t{ts}\t{dura}\t" + " ".join(current_group))
current_group = []
last_ts = ts
# timstamp
if(parts_count > 1):
ts = parts[0]
else:
ts = last_ts
if(not last_count):
last_ts = ts
# Fuege die aktuelle Zeile zur Gruppe hinzu
current_group.append(f"{parts[-1]}")
last_count = parts_count
# letzte
dura = int(ts) - int(last_ts)
output_lines.append(f"{parts_count-1}\t{ts}\t{dura}\t" + " ".join(current_group))
# Schreibe die Ausgabe in die output.txt Datei
with open(output_file, 'w') as outfile:
for output_line in output_lines:
outfile.write(output_line + '\n')
print(f"output written to {output_file}")
if __name__ == "__main__":
import sys
import os
infile = "serlog.txt"
if(len(sys.argv) > 1):
infile = sys.argv[1]
if(not os.path.exists(infile)):
print(f"{infile} not found.\nUsage: python serlog2log.py serlog_12345678.txt")
sys.exit()
outfile = infile + ".csv"
convert_file(infile, outfile)