I have a huge chunk of C++ code with thousands of lines like this:
case 14: //OrderSelect
Execute_OrderSelect();
break;
case 15: // OrderGetDouble
Execute_OrderGetDouble();
break;
case 16: //OrderGetInteger
Execute_OrderGetInteger();
break;
My task is to make them look like this:
case 14: Execute_OrderSelect(); break; // OrderSelect
case 15: Execute_OrderGetDouble(); break; // OrderGetDouble
case 16: Execute_OrderGetInteger(); break; // OrderGetInteger
Note, that both the Execute... and comments can be any string.
I suppose that schematically we could write the original like this:
AAA NN BBB
CCC
DDD
and try to turn it into: AAA NN CCC DDD BBB
.
I have tried unsuccessfully with all sorts of sed
expressions, and the best I could do was the trivial operation of combining the Execute...()
with the break;
, but was not able to move the comment around. I am thinking I am using the wrong tool for this, and perhaps awk
would be a better option or simpler to use?
Here are some awk
variables:
FNR The input record number in the current input file.
FS The input field separator, a space by default.
NF The number of fields in the current input record.
NR The total number of input records seen so far.
OFMT The output format for numbers, "%.6g", by default.
OFS The output field separator, a space by default.
ORS The output record separator, by default a newline.
RS The input record separator, by default a newline.
RT The record terminator. Gawk sets RT to the input
text that matched the character or regular expression
specified by RS.
RSTART The index of the first character matched by match(); 0 if no match
How can I make my day brighter?
Related Questions: