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 '^ *[13] '
^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 -m
ax 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:
2 ./dex/coll.sh
2 ./jimtcl/jim-config.h.in
it would be neater to replace the last line with:
... |
sed -ne's/^ *2 *//p'
...though.
F
do insed
? I can't find documentation on it anywhere. Or is that a typo? – Wildcard Nov 26 '15 at 19:44sed F filename
returnsunknown command: 'F'
. And looking through the entirety ofinfo sed
I don't see it mentioned anywhere. Did you test it? What version ofsed
are you using? EDIT: Ah, I see the link in your comment now. I suspected that's what it was supposed to do...but it doesn't work on my CentOS 6 vagrant box. – Wildcard Nov 26 '15 at 20:19F
was added insed 4.2.2
– don_crissti Nov 26 '15 at 20:22