Nem todas as expressões regulares em grep
são iguais a shell
. Para listar o disco com ? , use o seguinte
fdisk -l | grep 'sd?*'
Na verdade, o acima pode ser alcançado com a seguinte versão simplificada:
fdisk -l | grep sd
Você provavelmente quis usar egrep
:
fdisk -l | grep sd..?
Mas pode ser o suficiente para empregar a expressão regular correta:
fdisk -l | grep 'sd.\|sd..'
Explicação:
egrep
é equivalente a grep -E
, empregando uma versão diferente e aprimorada das expressões regulares .
.
significa qualquer caractere
\|
significa ou
Veja man grep:
-E, --extended-regexp Interpret PATTERN as an extended regular expression (ERE, see below). grep understands three different versions of regular expression syntax: “basic” (BRE), “extended” (ERE) and “perl” (PCRE). In GNU grep, there is no difference in available functionality between basic and extended syntaxes. In other implementations, basic regular expressions are less powerful. The following description applies to extended regular expressions; differences for basic regular expressions are summarized afterwards. Perl-compatible regular expressions give additional functionality, and are documented in pcresyntax(3) and pcrepattern(3), but work only if PCRE is available in the system. The period . matches any single character. Alternation Two regular expressions may be joined by the infix operator |; the resulting regular expression matches any string matching either alternate expression.