On Fri, May 31, 2024 at 11:18 PM Greg Wooledge wrote:
>
> On Fri, May 31, 2024 at 09:35:59PM -0500, David Wright wrote:
> > If a coloured ] is unimportant, I suppose you could use:
> >
> >   tree --du -Fh whatever | grep --color '][[:space:]][[:space:]].*/$'
>
> You don't need to count spaces.  Just '].*/$' would suffice.  We already
> know we want to start with the first ] character on the line, no matter
> how many spaces follow it.
>
> I really question the usefulness of colorizing the directory names,
> but since we're already this far down the rabbit hole, we might as
> well light some dynamite to make the hole deeper.  I'm sure it's safe!
>
> We're using GNU grep for coloring, so we can also use its PCRE syntax
> to do "lookbehind" voodoo:
>
>     tree --du -Fh /usr/local | grep --color -P '(?<=]).*/$'
>
> which means "start matching after a ] but don't include the ] in the
> match".

Or use  '\K' to cause previously matched characters to not be included
in the match:

   tree --du -Fah . | grep --color -P '[^]]*]  \K.*/$'

(which required entirely too much RTFMing to learn about '\K')

Regards,
Lee

Reply via email to