How do I delete multiline comment with @author

Viewed 86

I need to delete multiline comment with @author from all the java files. These comments are added by IDE and are in this format:

/**
 *
 * @author AuthorName
 */

I used sed and deleted the pattern and the next line using this command:

find . -name *.java | xargs sed -i '/@author AuthorName/,+1d'

But not sure how I can delete the pattern with previous 2 lines and the next line.

1 Answers

Using gnu sed you can use -z option to treat input delimited by NUL character and use:

find . -name '*.java' -exec sed -i -zE \
's~/\*\*[*[:space:]]+\* @author [^\n]*[*[:space:]]+*/\n*~~g' {} +

Regex pattern \*\*[*[:space:]]+\* @author [^\n]*[*[:space:]]+*/\n* will match a commented block that has * @author in the commented text.

Related