I parse a text file for the following line.
stp 11441 0 0 0 0
there are always 2 such line occurrences in the txt file. I am looking for the second value in the line (11441 here) and save it as a variable.
I have figured it out how to do such manipulations with only one variable. Here is the code I am using
import re with open('cpu.txt', 'r') as file: for line in file: match = re.search('stp \d{2,100}', line) if match: stp_queue1 = match.group().split( )[1] However, I can't get my head around how I specify a variable (stp_queue2 in that case) for the second time match occurrence.
In other words: if the file contains 2 following lines:
stp 11441 0 0 0 0 stp 20000 0 0 0 0 then stp_queue1 should be 11441 and stp_queue2 should be 20000 respectively.
Could you please help me with that?