Most probably, you have defined an alias somewhere in your shell startup files for regular user. Something along the lines
Code:
alias pcre2grep='pcre2grep --color=auto'
This alias is not defined for root. Compare the output of
and
Same goes for the environment variable GREP_COLORS. By default,
sudo sanitizes most of the environment. GREP_COLORS set for the regular user won't be seen by root unless included in the
env_keep list.
This is actually the case where cat abuse otherwise known as
UUOC might make sense:
Code:
sudo cat file_accessible_only_by_root|pcre2grep RE
Or just specify the
--color option explicitly (this will use default colors though):
Code:
sudo pcre2grep --color RE file_accessible_only_by_root