How can one remove code blocks starting with /** START */ and ending with /** END */ using sed non-greedily considering that code blocks are multiline and empty lines may occur within START-END blocks?
START marker single line comment
INPUT:
class MyClass {
keepField;
/** START */
deleteField;
/** END */
construct() {
/** START */
this.deleteField = 'delete';
/** END */
this.keepField = 'keep';
/** START */
this.deleteFunc();
/** END */
}
/** START */
deleteFunc() {
this.keepField = 'delete';
if (true) {
console.debug('Line before if statement is empty.');
}
} /** END */
}
OUTPUT:
class MyClass {
keepField;
construct() {
this.keepField = 'keep';
}
}
I have tried the following sed '/./{H;$!d} ; x ; s/START.*END//' MyClass.js as described in the sed manual > Multiline techniques section.
However, the above command is greedy in blocks when there are no empty lines and multiple START-END blocks (like in the constructor) and also empty lines of code are not taken into account inside START-END blocks (like in the deleteFunc function).
Any idea how the above can be solved with sed or any other command line tool such as awk?
START marker is block comment
INPUT:
class MyClass {
/**
* same code as above only this time the START block is
* multiline like below.
*/
/**
* START
*/
deleteFunc() {
this.keepField = 'delete';
if (true) {
console.debug('Line before if statement is empty.');
}
} /** END */
}
OUTPUT should also be:
class MyClass {
keepField;
construct() {
this.keepField = 'keep';
}
}
sed '/START/,/END/d' filesed '/\* START/,/END/d'sed '/\* START/,/END/d'doesn't seem to work for the edge-case.