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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -