It's important to note that the syntax inside square brackets is
fundamentally different from that in other parts of the regular expression. For
example, if you put a .
inside square brackets, it allows the
square brackets to match a literal .
, just like the 1
and 2
in the examples above. In comparison, a literal .
outside the square brackets is interpreted as a metacharacter unless
prefixed by a \
. We can take advantage of this fact to print a
list of all lines in /etc/fstab
that contain the literal string
dev.hda
by typing:
$ grep dev[.]hda /etc/fstab
Alternately, we could also type:
$ grep "dev\.hda" /etc/fstab
Neither regular expressions are likely to match any lines in your /etc/fstab
file.