On CentOS 8, this grep
expresssion does not return matched strings:
% dmidecode -t memory | grep -E '^[ t]+Size: [0-9]+'
However this one does return matched lines correctly (on the same distro):
% dmidecode -t memory | grep -E '^[[:space:]]+Size: [0-9]+'
What is the reason of such behaviour? As you can see both times grep
is invoked in extended regexp mode.
2
Answers
Use
[[:blank:]]
which matches space char and tab char. You can omit-E
too:The issue here is the
t
character sequence. This does not match a tab character in agrep
regular expression, it matches the charactert
(Doesn’t matter if it’s basic or extended dialect RE). It’s not treated as a special escape sequence the way it is by some other tools (Including GNUgrep
using the PCRE dialect).Witness: