I have input table as below
module input output type func
AOIO A1,A2,B Z comb ((!A1+!A2) B)
AN2 A1,A2 ZN comb (A1 A2)
AIO A1,A2,A3 Z comb ((A1 A2)+A3)
NOR A1,A2 ,B Z comb (!((A1 A2)+B))
BUF I Q seq I
CLK I QN seq IN
BND
INV IN Z comb (!I)
I want above table to display in below format
module input output type func path
AOIO A1,A2,B Z comb ((!A1+!A2) B) 3
AN2 A1,A2 ZN comb (A1 A2) 1
AIO A1,A2,A3 Z comb ((A1 A2)+A3) 2
NOR A1,A2 ,B Z comb (!((A1 A2)+B)) 3
BUF I Q seq I 1
CLK I QN seq IN 1
BND 0
INV IN Z comb (!I) 1
The logic to get path is
count the opening bracket '('.
If
(ends with!then assign path ascount+1as in AO case. If it doesn't have!then assign path as count i.e only no.of opening bracket (AN,AI case). If it does not have opening bracket assign path as 1 (BUF,CLK case). If it doesn't have func, assign path as 0(BND case). If!is present between opening brackets(then ignore!and count the number of opening brackets and assign it to path (as in NOR case). And whenever there is(!I)present in func, assign path as 1 always.
Can anybody help me building logic for this. I can count for ( using below code and gets value of no. of ( And then can check for above conditions using
sed 's/[^(]//g' file | awk '{ print length} | awk '{ if ($2~/^(*!/ ) print $3 length+1 ; elseif($2~/^( / ) print $3 length; elseif ($2 !~ /(/ print $3 "1"; elseif ($2~/(!I)/ ) print $3 "1"
But here in code i am not getting count of '( ' and getting error. And I am not getting logic how can i count opening bracket if '!' is in between.