Outra solução que usa awk .
Crie um novo script changeLicense.awk
assim:
{
if (match($1,"^/\*.")!=0) {
i = 0; flag = "false";
comment[i++] = $0;
while(getline > 0) {
if (match($0,"Copyright") != 0) flag = "true";
comment[i++] = $0;
if (match($0,"\*/$")!=0) {
if (flag == "false") {
for (J=0; J<i; J++) print comment[J];
}
else {
while ((getline line < newLicense) > 0)
print line;
close(newLicense);
}
next;
}
}
}
print;
}
Este script procura o bloco de linhas dentro de /*
e */
e se o bloco de linhas comentadas contiver a sequência "Copyright", substitua o bloco pelo conteúdo do arquivo newLicense, caso contrário, preserve o comentário.
Para alterar a licença em todos os arquivos do seu projeto:
find /path/project -name "*.cpp" -exec bash -c 'awk -f /path/changeLicense.awk -v newLicense=/path/fileWithNewContent $1 > $1.new; mv $1.new $1' _ {} \;
Este script executa changeLicense.awk
em cada .cpp
arquivo encontrado em /path/project
, coloca o resultado em .new
arquivo e substitui o original .cpp
Testado no lubuntu 12.04