Removing multiline text from multiple files

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

The pattern I'm looking for is

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

but matches the lines

Is there a way that sed [or the commonly used editor on Windows / Linux] can search / replace for a multi-line pattern?

+3
source share
3 answers

Here's the corresponding breakpoint in my favorite sed tutorial.

+3
source

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

. , , , .

:

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

. (?: ./ , ! . -0777 slurp -n .

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

0

, - . .

awk , . diff, sed .

awk "/^\* \* ProjectName /,/ USA\.$/" input.txt \
  | diff - input.txt \
  | sed -n -e"s/^> //p" \
  >output.txt

: , - , - .

0

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


All Articles