views:

385

answers:

2

I have a bunch of java files from which I want to remove the javadoc lines with the license [am changing it on my code].

The pattern I am looking for is

^\* \* ProjectName .* USA\.$

but matched across lines

Is there a way sed [or a commonly used editor in Windows/Linux] can do a search/replace for a multiline pattern?

+2  A: 

Here's the appropriate reference point in my favorite sed tutorial.

Adam Bellaire
A: 

Yes. Are you using sed, awk, perl, or something else to solve this problem?

Most regular expression tools allow you to specify multi-line patterns. Just be careful with regular expressions that are too greedy, or they'll match the code between comments if it exists.

Here's an example:

/\*(?:.|[\r\n])*?\*/
perl -0777ne 'print m!/\*(?:.|[\r\n])*?\*/!g;' <file>

Prints out all the comments run together. The (?: notation must be used for non-capturing parenthesis. / does not have to be escaped because ! delimits the expression. -0777 is used to enable slurp mode and -n enables automatic reading.

(From: http://ostermiller.org/findcomment.html )

Pete