In my code file I have several lines asT V= X T(A);
And I want the text after =
to be replaced as X(T,A)
with some help I got this pattern s/X\s+([^\(]*)\(/X(\1,/g;
for find and replace it works great but the problem is when we have no args to pass for T
Ex.T V= X T();
then after replacement it will be like X(T,)
(see the extra comma) I knew it's because of /X(\1,
can somebody help me rid of that extra comma, Sadly I am no regex guy.
Is there any sort of conditional we could have to say if the ()
is empty then do X(\1/g
rather than /X(\1,/g
s
:sed -E 's/X\s+([^\(]*)\(\)/X(\1)/g;s/X\s+([^\(]*)\(/X(\1,/g'
the 1st one will only replace theT()
stuff, the 2nd one will replace the rest (as theT()
was already changed and no longer matches the regex)