开发者

List all the files which do not contain a particular string

开发者 https://www.devze.com 2023-04-05 20:53 出处:网络
I would like to know which files do not include a particular header file in C. For example: file1.c #include \"stdio.h\"

I would like to know which files do not include a particular header file in C.

For example:

file1.c

#include "stdio.h"
#include "my.h"

...

file2.c

#include "stdio.h"

....

I would like to find out simila开发者_开发问答r files (like file2.c) which do not contain #include "my.h".


On Unix systems:

grep -L '#include.*my\.h' *.c


shopt -s nullglob
for file in *.c
do
   if grep -q "my.h" "$file" ;then
     continue
   else
      echo "found file that don't have my.h"
   fi
done

Or you could use:

grep -L "my.h" *.c

if you have nothing else to process except to echo out file names. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消