I would like to update all the files (.c / .h) of my project, using a script (for Linux), to add a fixed header of the following type:
How can I do ?Code:/*
* <File Name>
* <Author>: <Date>:
*
* Description:
*
* History:
*
*/
Printable View
I would like to update all the files (.c / .h) of my project, using a script (for Linux), to add a fixed header of the following type:
How can I do ?Code:/*
* <File Name>
* <Author>: <Date>:
*
* Description:
*
* History:
*
*/
Something like this maybe:
Running the script:Code:cat $1 $2 > .tmp && mv .tmp $2
Code:prepend preamble.txt file.txt
Yes, thank:
Code:#!/bin/bash
for file in *.c; do
cat $1 $file > .tmp && mv .tmp $file
done
Now it is a matter of reading the file name and inserting it in the header, then inserting the name of the author and reading the date of creation of the file, always inserting everything in the header. How you do it ?
At the moment I wrote this:
instead of $ date I need to be able to use the bash date command to get the current bash script launch date. How should I write it ?Code:#!/bin/bash
for file in *.c; do
echo "/*" > intestazione.txt
echo " * File Name: " $file >> intestazione.txt
echo " *" >> intestazione.txt
echo " * Author: Giorgio Guglielmone Date: " $date >> intestazione.txt
echo " *" >> intestazione.txt
echo " * Description:" >> intestazione.txt
echo " *" >> intestazione.txt
echo " * History:" >> intestazione.txt
echo " *" >> intestazione.txt
echo "*/" >> intestazione.txt
cat intestazione.txt $file > .tmp && mv .tmp $file
done
Code:author='Your name here'
for file in *.c; do
sed -i "s/<File Name>/$file/;s/<Author>/$author/;s/<Date>/$(date)/" $file
done
Code:echo " * Author: Giorgio Guglielmone Date: " `date` >> intestazione.txt