Adding Headers to Files in a Batch

Valery just posted a blog article about a tool to insert headers in a bunch of files. I don’t have too much to say about that, but the comment form on the blog didn’t want me to post the following (a server error message about a potentially dangerous form post, lol), so I thought I’d just put it in my own blog instead. Here’s the comment I wanted to post: Wow! That’s some solution for a tiny problem… How about a small shell script:

#!/bin/sh

for file in *.cpp; do
  cat my\_new\_header > $file.new
  cat $file >> $file.new
  mv -f $file.new $file
done

Certainly not the most elegant solution, but just as certainly it does the job and takes only a few seconds to write when needed.

Sorry, this blog does not support comments.

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.