• Source
    1. #
    2. #Write a shell script to add the statement #include <stdio.h> at the beginning of every C source file in
    3. #current directory containing printf and fprintf.
    4. #
    5.  
    6. clear
    7.  
    8. echo -n "Enter directory name :"
    9. read directory
    10.  
    11. if [ ! -d $directory ]
    12. then
    13. echo "Directory does not exist"
    14. else
    15. for i in $(find $directory -name "*.[cC]")
    16. do
    17. count="$(cat $i | grep -icw 'printf\|fprintf')"
    18. if [ $count -gt 0 ]
    19. then
    20. echo "$(sed '1i\#include<stdio.h>\' $i)" > $i
    21. fi
    22. echo $i
    23. done
    24. fi