views:

40

answers:

1

I'm trying to determine which header declares a specific function. I've used grep to find instances of the function's use; now, I want to find which header is included by all the files. I'm aware of the comm utility; however, it can only compare two sorted files. Is there a Unix utility that can find the common lines between an arbitrary number of unsorted files, or must I write my own?

A: 
 cat *.c | sort | uniq -c | grep -e '^ *COUNT #include'

where COUNT is the number of files passed to cat. In playing around, I used this variant to see what files I #include at least 10 times:

 cat *.c | sort | uniq -c | grep -e '^ *[0-9][0-9]\+ #include'
drawnonward
This won't find a header which is indirectly included (foo.c includes foo.h which includes bar.h, while baz.c includes baz.h which includes bar.h).
Borealid
True, but neither would the suggested comm. I took that as license to rely on strict equality and to ignore headers including other headers. Without some help, mismatched whitespace or comments would foil `uniq -c` too.
drawnonward