I was trying to write a script to add a trademark header to my .cpp file. my solution is as follows.
cat trademark.txt test.cpp > new_test.cpp && mv new_test.cpp test.cpp
However, wanted to know if there is a better way of doing this.
Go to Insert > Header & Footer. Add or header or footer text.
You can use awk like this:
awk 'NR==FNR && !h {print;h=1;} NR!=FNR{print}' headerFile mainFile > tmpFile
mv tmpFile mainFile
Using vim/vi:
vim +'0r headerFile|wq' mainFile 2>/dev/null
Using GNU sed:
sed -i.bak -e '2{x;G};1{h;rheaderFile' -e 'd}' mainFile
Using non-GNU sed:
HDR=$(head -1 headerFile) && sed -i.bak "1s/^/$HDR/" mainFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With