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


clear

grep -l -e "printf" -e "fprintf"  *.c > temp.txt

#grep
#    -l, --files-with-matches
#              Suppress normal output; instead print the  name  of  each  input
#           file  from  which  output would normally have been printed.

#    -e PATTERN, --regexp=PATTERN
#             Use PATTERN as  the  pattern.   This  can  be  used  to  specify
#          multiple search patterns


for i in `cat temp.txt`
do  
     sed '1i\#include<stdio .h=".h">' $i &gt; temp2.txt
    cat temp2.txt &gt; $i
    echo "Successfully Added..."
done

# sed i  :
#     -i[SUFFIX], --in-place[=SUFFIX]
#              edit files in place (makes backup if extension supplied)


# sed l  :
#     -l N, --line-length=N
#              specify the desired line-wrap length for the `l' command
</stdio>

0 comments:

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.