Apr-05-2022, 06:58 PM
Hi
I'm a python beginner and would like to extract parts of a log-file and put it in a dataframe.
I tryed something, but it is not what I want.
Log-File content looks like this:
Thanks for help!
I'm a python beginner and would like to extract parts of a log-file and put it in a dataframe.
I tryed something, but it is not what I want.
Log-File content looks like this:
Output:----------------------------------------------------------
Model: Hamilton-C1
S/N: 25576
Export timestamp: 2020-09-17_11-03-40
SW-Version: 2.2.9
I want extract only Hamilton-C1, 25576, 2020-09-17_11-03-40, 2.2.9#list result = [] #function def appendlines(line, result, word): if line.startswith(word): del result[:] result.append(line) return line, result with open(file, "r") as lines: for line in lines: appendlines(line, result, ":") new_result = [line.split() for line in result[1:5]] print(new_result)
Output:[['Model:', 'Hamilton-C1'], ['S/N:', '25455'], ['Export', 'timestamp:', '2020-09-16_21-12-40'], ['SW-Version:', '2.2.9']]
I want only this output:Output:[['Hamilton-C1'], ['25455'], ['2020-09-16_21-12-40'], ['2.2.9']]
How I have to change my code?Thanks for help!