Add headers recursive on top of each code file

Bourne Again SHell

In various situations during the work on a project, it could happen that one is required to add a header to a lot of source code files.

Since programmers are usually lazy — eh, interested to work efficiently — they won’t open every file and copy it manually. Once again, the Bash can help us.

For example, a copyright notice in all C/C++ files:

find . -name \*.{c,cpp,h,hpp} | xargs sed -i "1i/*Copyright .... you can also use newlines, tabs etc....\n\t..*/"

Or, to add a import statement in all python files:

find . -name \*.py | xargs sed -i "1iimport fancy.new.packet"

Important in the argument for sed is the leading 1i, which means:

The combination of find and xargs executes the command recursive in the current directory. The \*.XYZ is a RegEx to match the correct file types.

Based on helpful posts on Stackoverflow.

You have another opinion?
Great! Then let's reduce the fallacy together!


Why are there no comments?