I am trying to match a multiline pattern using a shell command through python.
I am able to match using the shell commands but I am not able to pass this command through the Python subprocess.call or the os.system modules.
My file looks something like this:
(CELL
(CELLTYPE "NAND_2X1")
(INSTANCE U2)
(DELAY
(ABSOLUTE
(IOPATH A1 ZN (0.02700::0.02700) (0.01012::0.01012))
(IOPATH A2 ZN (0.02944::0.02944) (0.00930::0.00930))
)
)
)
No, I am trying to extract this:
(INSTANCE U2)
(DELAY
(ABSOLUTE
(IOPATH A1 ZN (0.02700::0.02700) (0.01012::0.01012))
(IOPATH A2 ZN (0.02944::0.02944) (0.00930::0.00930))
)
)
using this regex:
pcregrep -M -n 'INSTANCE U2((?!^\)).*\n)+' sdf/c1_syn_buf2.sdf
wherein U2 is the search string and sdf/c1_syn_buf2.sdf is the file name
In Python, I have defined a function to which I will pass the search string and the file name as I have to do this operation multiple times.
I am unable to successfully execute this as a shell command using something like:
>>>b = subprocess.call(['pcregrep','-M','-n','INSTANCE '+arg, '\)((?!^\).*\n)+ '+file ])
pcregrep: Failed to open \)((?!^\).*
)+ /home/sanjay/thesis/code/sdf/c7552_syn_buf0.sdf: No such file or directory
When I actually put in the argument (U2 in this case) name and the file name, I am able to get the desired output.
EDIT If pcregrep is not friendly enough, here is the awk command:
awk '/INSTANCE U2/,/^)\n?/' sdf/c1_syn_buf2.sdf
Returns the same.
Can someone please help me with this?