This groups by basename and grep output:
]# grep -ro '#include' include/ |sed -E 's|.*/(.*:)|\1|' |uniq -c |sort|tail -n7
28 kvm_host.h:#include
28 mm.h:#include
29 ib_verbs.h:#include
31 net_namespace.h:#include
32 sock.h:#include
44 fs.h:#include
48 drmP.h:#include
I used grep -o
to get some duplicates. Same time it leaves out the slashes...
If the names contain :
the sed will not work correctly. The regex first throws away everything until the last /
, then stores everything until a :
as \1
.
I used -E
because of the (subexpression) and |
because of the slash.
The subexpression (.*:)
is a bit simple (will fail if a grepped line contains a colon). If you leave out the colon, it will fail when the line contains a slash.
Looking at this output I say this is impossible in theory (to parse grep's output in that way):
]# grep -r "" d*
d:/ir:/afile...in file "d"
d:/ir:/afile...in file "ir"
This is identical. I needed a dir with a colon at the end and a file with overlapping name and contents.
]# ls d*
d
'd:':
ir
grep --color
makes the difference!
The include
directory is the one from the linux kernel source. One full line in one include-file looks like this.
]# grep -rH '#incl' include/linux/aio.h
include/linux/aio.h:#include <linux/aio_abi.h>
dir1/a.txt
anddir2/a.txt
are the same and you want onlya.txt
as a result? – pLumo Apr 15 '20 at 6:53a.txt:asdf
, right? – pLumo Apr 15 '20 at 7:06