linux - Remove redundant braces from code -
i trying use tr
command or similar command perform specific text manipulation block:
if (/*condition*/) { statement1; } int a=3; if (a) { statement1; statement2; } else { statement1; statement2; statement3; statement4; ///may more lines }
i want remove single line commands , this:
if (/*condition*/) statement1; int a=3; if (a) { statement1; statement2; } else { statement1; statement2; statement3; statement4; ///may more lines }
i've tried tr -s '{}' ' ' <file.txt
squeezes of braces, not specific single line format.
thanks
you can set record separator either {
or }
, check how many fields have. if there more one, print brackets around:
$ awk -v rs=[{}] 'nf>1{$0="{"$0"}"}1' file if(true) statement; if(false) { statement1; statement2; }
Comments
Post a Comment