I'm looking for a shell script (Bash) that adds or replaces copyright text at the beginning of the file (for .c
and .h
files).
It should search and add or replace the copyright text block for all the .c
and .h
files from the parent directory where I execute my script.
Existing copyright text:
/* --------------------------------------------------
Copyright 2014 Author name
All rights reserved
----------------------------------------------------*/
New Copyright text.
/* Copy right text bla bla bla
* some license text bla bla bla
* All rights reserved xyz xyz */
Note
Copyright text should be added at the beginning of the file (
.c
and.h
) only and always the existing copyright text will be in the beginning of the file.It should search and add or replace for all the
.c
and.h
files within the parent directories and sub directories.
EDIT
This is what I tried:
for file in `find . -type f -name "*.h"`
do
echo $file
if grep -qRin " ----------------------------------------------------------------------\*\/" $file
then
echo "Replaced License Text"
sed '1,/^ ----------------------------------------------------------------------\*\/$/d' < $file | cat licence_file - > $file.new
mv $file.new $file
else
cat licence_file $file >$file.new && mv $file.new $file
echo "Added License Test"
fi
done
Licence_file contains my new license text.