import sys import re for ln in sys.stdin: m = re.match(r'^(.*?)\s+on\s+CPU.*(?<=\sCPU)\s+(\d+)\s*$', ln); if m is not None: print m.groups();
some other line here TrnIq: Thread on CPU 37 TrnIq: Thread on CPU 37 but will be moved to CPU 44 IP-Thread on CPU 33 FANOUT Thread on CPU 37 Filter-Thread on CPU 38 but will be moved to CPU 51 TRN TMR Test 2 Supervisor Thread on CPU 34 HomographyWarp Traking Thread[0] on CPU 26
('TrnIq: Thread', '37')
('TrnIq: Thread', '44')
('IP-Thread', '33')
('FANOUT Thread', '37')
('Filter-Thread', '51')
('TRN TMR Test 2 Supervisor Thread', '34')
('HomographyWarp Traking Thread[0]', '26')