I have a file containing these lines
Entry : 12300000
F Blocks: 0x00000020 0x00000000 0x000a1b00
S Blocks: 0x00100000 0x0000001c 0x00000150
Using a shell script, the hex values from line starting with F Blocks: can be extracted using the line below :
blocks="$(sed -nE 's/F Blocks:[\t ]+(0x)?([0-9a-f]+)[ ]+(0x)?([0-9a-f]+)[ ]+(0x)?([0-9a-f]+)/0x\2 0x\4 0x\6/p' filename)"
I would like to do the same extract in a Python script, using the subprocess module
import subprocess
sed_cmd = ['sed', '-n', '-E', "s/F Blocks:[\t ]+(0x)?([0-9a-f]+)[ ]+(0x)?([0-9a-f]+)[ ]+(0x)?([0-9a-f]+)/0x\\2 0x\\4 0x\\6/p", 'filename']
proc = subprocess.Popen(sed_cmd, stdout=subprocess.PIPE)
blocks = proc.stdout.read()
Is there a best practice to extract data and the output in a variable, or could it be simplify ?