To all c and h files in a project with subdirectories.
Logalloc is a tool to log all *alloc and free's in a text file, it defines the *alloc funtions new. #define malloc(size) logmalloc(size,__FILE__,__LINE__)
with perl
perl -pi -e "s:^:#ifdef MALLOC_TRACE\n#include <logalloc.h>\n#endif\n:" *.test
almost right but it replaces every begining of a line(^) with my string, it only needs to replace the 1st line!
with sed
sed -e "1s:^:#ifdef MALLOC_TRACE\n#include <logalloc.h>\n#endif\n:" *.test
sed replaces only the first line (notice the 1 infront of the 's'. (the perl script dosent support the 1)
But sed dosent recognize the newlines, i dont know how to define them in the cshell.
2 questions:
----------------
1.how do i declare a \n (newline) in the cshell?
how can i limit my perl script to only one (the first) line?