Code
find /tmp/ -type f \
\( -name "*.h" \) -o \( -name "*.cpp" \) -o \
\( \! -name "*.bak" \) -exec \
sed -i '1s/^/#include <stdint.h>\n/' {} +
I am not completely sure that this is the right way to go. I write directly to the file without taking temporary files. I want to replace the beginning of the line in .h and .cpp files with but not in .bak files.
How can you make efficient replacement? Note: I am using GNU sed.
I tried Terdon's command and the insertion is applied to wrong files:
$ cat test.sh
gfind /tmp/ -type f \
\( -name "*.h" -o -name "*.cpp" -o ! -name "*.bak" \) \
-exec gsed -i '1s/^/#include <stdint.h>\n/' {} +
$ sh test.sh
$ cat test.sh
#include <stdint.h>
gfind /tmp/ -type f \
\( -name "*.h" -o -name "*.cpp" -o ! -name "*.bak" \) \
-exec gsed -i '1s/^/#include <stdint.h>\n/' {} +
where all commands are GNU: find and sed.