Hello all, I am in week two of learning Bash and I am lost!
My first task is to search the current directory for files with the extensions .c and .cc, and search for the strings printf and fprintf within those files. IF the print statements are found, then I am to add in a header if it's not already there.
This is where I am at so far-- I am finding the man pages hard to understand and googling everything has become overwhelming!
Can anyone maybe just give me a few hints? My errors that I have run into so far is that I can't seem to get the right syntax when I am piping my 'ls' results to my grep in the outer for loop...so I eventually decided to work from the inside out...but now I can't seem to get the right type of arguements for my inner grep :-(
for FILE in `ls *.cc *.c` # | egrep "printf\ | fprintf"
echo $FILE; #to make sure ls worked
if [ grep -Fqx '#include <stdio.h>' "$FILE" ]
#include <stdio.h> ' file > new_file;
mv new_file file;