I need to copy timing window into a variable from line of .txt file using Python.
Input file:
[Fri Dec 07 18:50:16.775 2018] [ 3.610065] dwc3 e2d00000.usb_core: SUCCESS allocating dump_regset memory
[Fri Dec 07 18:50:16.775 2018] [ 3.610770] dwc3 e2d00000.usb_core: Soft reset timeout -29631
[Fri Dec 07 18:50:16.775 2018] [ 3.614879] dwc3 e2d00000.usb_core: Dump USB registers
So from the above input file i need "3.610770" value to be copied into integer variable because that line contains "Soft reset timeout" string.
I have managed to write some portion of code but unable to proceed further.
Python script snippet:
import sys
inFile = sys.argv[1]
with open(inFile) as fp:
line = fp.readline()
while line:
if "Soft reset timeout" in line:
#print line
if "[ " in line:
#To Do...
#if "Dump USB registers" in line:
line = fp.readline()
3.610770
as an integer would result in reading3
. Is that really what you are looking for? Have you tried looking for an answer to your question yet?