I want to add a sentence to header of a file using bash script, I tried
echo "#define Block $i">>mypro.cpp
but it add '#define Block $i' to it's end. Thanks in advance
You can used sed
:
[romano:~/tmp] % echo test >! test.c
[romano:~/tmp] % sed -i -e "1i #include" test.c
[romano:~/tmp] % cat test.c
#include
test
...just take care of the correct quoting.
More verbose: sed -i
means to edit the file (the last argument) in place; the command "NiSomething"
insert Something at line N.
PD this works on Linux and (GNU sed) 4.2.2 --- POSIX sed
require a stricter syntax.