if your filenames are fairly sane, and you can delimit on both
: and a newline, then:
grep -m3 '' ./* ./*/* |
cut -d: -f1 | uniq -c |
grep -v '^ * '
^that command will list all not-dot files in the current directory and in all immediate child directories which contain only two lines.
You don't really need to worry about sorting for
uniq, because globs are sorted. I use the GNU
-max match option because it is much faster if
grep quits at the third input line than it is if it continues through to the end, but it will work without it as well. The idea is to get
grep to print the filenames for each line they contain, then to count the occurences of each filename in its output, and then to filter out anything more or less than 2.
I ran it against some random source code dirs, and, of all of them, I had two files which contained only the two lines:
it would be neater to replace the last line with:
sed -ne's/^ *2 *//p'