Loading...

Bash Collection – Howto recursively replace file headers of source files

Gerhard Gappmeier has submitted a really cool and useful bash script, that he is using for years now. It is very helpful for developers.

This scripts can replace file headers from C/C++/JAVA header and source files. Often it’s necessary to replace the license conditions in multiple source files, update the copyright year, or simply make all file headers consistent. This can be a lot of work, so that’s why I wrote this scripts.

How it works: The BASH script replace_header.sh is a simple wrapper that executes the AWK script remove_header.awk which implements a basic state machine for recognizing C/C++/JAVA comments (“// …”, “/* … */). All comments at the beginning of the file – also when spanning over multiple lines – are ignored until the first line without comment is reached. The AWK file ignores all this comments, and prints the rest of the file unchanged. The BASH script creates a new file with your new header.template and adds your code without the old file header to the newly created file. Afterwards it copies the new file over the old one.

Example usage:

 

You can find and download the script here 

 

Thanks Gerhard!

 

.

Share

About Christin Löhner (Linux Counter)


   One Comment


  1. rjn0
      2015-09-10

    Add “-type f” to “find” only “files”…

Leave a Reply