Write a shell script to add the statement #include at the beginning of every C source file in current directory containing printf and fprintf.

echo include line #include<stdio.h> in all c file

cFile=find . -name *.c

str=”#include<stdio.h>”

for i in $cFile

do

pCount=grep -c '^printf' $i

fCount=grep -c '^fprintf' $i

count=grep -c '^#include<stdio.h>' $i

if [ $pCount -gt 0 -a $fCount -gt 0 -a $count -eq 0 ]

then

echo $str > temp

cat $i >> temp

rm $i

cp temp $i

cat $i

else

echo “#include is already present in the file $i”

fi

done

 

OUTPUT::

 

include line

#include is already present in the file ./abc.c

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.