How to remove multi-line comment using @author

I need to remove a multi-line comment with @author from all java files. These comments are added by the IDE and are in this format:

/ **
 *
 * @author AuthorName
 * /

I used sed and removed the template and the following line using the following command:

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

But I don’t know how I can delete a template with the previous two lines and the next line.

+4
source share
1 answer

Using gnu sed, you can use the option -zto process input limited to the NUL character and use:

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

The regex pattern \*\*[*[:space:]]+\* @author [^\n]*[*[:space:]]+*/\n*will correspond to the comment block c * @authorin the comments.

+3
source

Source: https://habr.com/ru/post/1688881/


All Articles