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?
Asked
Active
Viewed 2,148 times
3

Community
- 1
- 1

Evan Kroske
- 4,506
- 12
- 40
- 59
1 Answers
1
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
- 53,459
- 16
- 107
- 112
-
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 Jul 10 '10 at 04:45
-
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 Jul 10 '10 at 04:49