De acordo com a explicação nos comentários:
sed "
# for lines which starts with if
/^if\b/{
/==/! {
# add logic statement to first alphanums after (
s/\((\w\+\)/ == 1b'1 /
# add logic statement to second alphanums after & if it is present
s/\(&\!\?(\?\w\+\)/ == 1b'1 /
# if ! sign in section replace 1 by 0 at the end of statement
s/\!(\([^']*'\)1 )/ /g
}
}
" file
Outra variante - remova o everithing, exceto a parte que será modificada, altere-a, em vez de construir a linha completa de volta:
sed "/^if\b/{
/==/!{
h
s/if (.*) //
x
s/if (\(.*\)) (.*//
s/\w\+/& == 1'b1 /g
s/!(\(.*\)1 )/ /g
s/.*/if (&)/
G
s/\n/ /
}
}" file