-1

I am running a commercial opensource CRM that is a pain to keep in VCS. At the top of every file that isn't "open source"... they put a copywrite like so:

/*********************************************************************************** * Copyright (C) 2011-2015 Company Inc. All Rights Reserved. * * blah blah blah that changes every so often * ******a variable number of stars*****************/

Whenever they change the copyright text/dates, every file I have looks like its changed in git.

So my question How do I do this ( https://stackoverflow.com/a/22171275/140541 ) that will remove the copyright block... just so I don't have to see it in my git and don't have to worry about it when it changes?

Thanks!

UPDATED question.

I really need a sed statement that will turn this:

<?php 
/***************************************************************
 * Copyright (C) 2011-2015 Company Inc. All Rights Reserved.
 *
 * blah blah blah that changes every so often
 *
 ******************************/

some code 

/***
 * foo here
 */

Into this:

<?php    
/***************************************************************
 * some text here
 ******************************/

some code 

/***
 * foo here
 */

BUT it needs to only work if the first comment in a file has the word "Copyright" in it.

Community
  • 1
  • 1
that0n3guy
  • 577
  • 4
  • 13

1 Answers1

1

As I say repeatedly - sed is NOT for anything involving multiple lines. That's what awk was invented to handle:

$ cat tst.awk
inCmt && /\*\// {
    if (cmt ~ /Copyright/) {
        sub(/\n.*/,"\n * some text here\n",cmt)
    }
    $0 = cmt $0
    inCmt=0
    done=1
}
!done && /\/\*/ { inCmt=1 }
inCmt { cmt = cmt $0 ORS; next }
{ print }

.

$ cat file1
<?php
/***************************************************************
 * Copyright (C) 2011-2015 Company Inc. All Rights Reserved.
 *
 * blah blah blah that changes every so often
 *
 ******************************/

some code

/***
 * foo here
 */

$ awk -f tst.awk file1
<?php
/***************************************************************
 * some text here
 ******************************/

some code

/***
 * foo here
 */

.

$ cat file2
<?php
/***************************************************************
 * blahblahbla (C) 2011-2015 Company Inc. All Rights Reserved.
 *
 * blah blah blah that changes every so often
 *
 ******************************/

some code

/***
 * foo here
 */

$ awk -f tst.awk file2
<?php
/***************************************************************
 * blahblahbla (C) 2011-2015 Company Inc. All Rights Reserved.
 *
 * blah blah blah that changes every so often
 *
 ******************************/

some code

/***
 * foo here
 */
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • @ghoti thanks but I had missed the requirement to only process comments if the contained the word `Copyright`. Updated now. Not as short but still sweet :-). – Ed Morton May 22 '15 at 21:00