It's just a ~100KB file, so it fast enough.
I simplified the script with a function:
I simplified the script with a function:
import re #pip install pyperclip import pyperclip def SearchAndTell(MYFILE,mypattern): p = re.compile(mypattern) for line in reversed(open(MYFILE).readlines()): m = p.search(line.rstrip()) if m: return m.group(1) break #needed? INPUTFILE = "log.txt" clipb = None pattern = "^START_A.+to (.+?) \(.+$" clipb = f"-ss {SearchAndTell(INPUTFILE,pattern)} ".replace(",",".") pattern = "^START_B.+to (.+?) \(.+$" clipb += f"-to {SearchAndTell(INPUTFILE,pattern)}".replace(",",".") pyperclip.copy(clipb)FWIW, here's the batch script:
grep -Poha "^START_A.+$" log.txt | sed -r "s@^.+ to (.+?) \(.+$@-ss \1@" | sed -r "s@,@.@g" | tail -1 grep -Poha "^START_B.+$" log.txt | sed -r "s@^.+ to (.+?) \(.+$@-to \1@" | sed -r "s@,@.@g" | tail -1