1

this is a sample output of ls

$ ls -lAF
-rw-------  1 martin martin  168 Jan 25 23:26 aaa
-rw-------  1 martin martin  168 Jan 25 23:26 bbb
-rw-------  1 martin martin  168 Jan 25 23:26 ccc

I would like to colorize the user and group entries. However, my syntax only colorizes user,but not the group:

ls -lAF | grep --color -P '^\S+\s+\S+\s+\K\S+'

I don't understand what the \K exactly means. How could I match both martin martin in my sample output?

3

\K marks the start of the region to color.

See man pcrepattern for details.

The escape sequence \K causes any previously matched characters not to be included in the final matched sequence.

That means you need:

ls -lAF | grep --color -P '^\S+\s+\S+\s+\K\S+\s+\S+'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.