# \[OT\] How to prepend copyright notices to each source file

**URL:** <https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877>\
**Category:** Rails\
**Created:** [February 11, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877 "2006-02-11T16:20:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 11, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877/1 "2006-02-11T16:20:24Z")

</div>

Sorry for the off-topic post, but I guess someone else may hit the same  
issue…

Having developed a rails application, I now need to put GPL text and a  
copyright notice at the start of each source file. For the .rb files,  
this  
will look like:

# Copyright 2006 Robert J…

and for the .rhtml files it will look like:

\<!-- Copyright 2006 Robert J.......... Can anyone think of a neat way to do this prepending programatically on Linux, rather than by hand? I'm sure I can be done with awk, sed, grep etc. Thanks in advance, -- Robert J.

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 11, 2006, 5:18pm UTC](https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877/2 "2006-02-11T17:18:21Z")

</div>

make a script addhead in root directory:

#!/bin/sh  
cat $2 $1 \> $1.tmp  
mv $1.tmp $1

then execute  
find . -name “\*.rb” -exec ./addhead {} header.txt ;

Michael J.

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 12, 2006, 12:13am UTC](https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877/3 "2006-02-12T00:13:55Z")

</div>

If you’re using a layout file, put it in there.

If you’re resorting to sed/awk/etc. for stuff like this, personally  
I’d think that your design needs to be looked at and possibly  
refactored.

Layouts are incredibly handy…

Regards

Dave M.

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 12, 2006, 8:04am UTC](https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877/4 "2006-02-12T08:04:01Z")

</div>

On 12-feb-2006, at 0:13, David M. wrote:

> > Having developed a rails application, I now need to put GPL text  
> > and a  
> > copyright notice at the start of each source file.

> If you’re using a layout file, put it in there.
> 
> If you’re resorting to sed/awk/etc. for stuff like this, personally  
> I’d think that your design needs to be looked at and possibly  
> refactored.

Refactored? He wanted the notice “at the start of each source file.”

–  
Regards, Charles.

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 12, 2006, 9:55am UTC](https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877/5 "2006-02-12T09:55:50Z")

</div>

Thanks Michael - works like a charm. So simple too.

Robert

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 12, 2006, 8:27am UTC](https://www.ruby-forum.com/t/ot-how-to-prepend-copyright-notices-to-each-source-file/65877/6 "2006-02-12T08:27:47Z")

</div>

Ah, my mistake - I read it as though he wanted to have a copyright  
notice on each (published) page.
