|
1、使用 \ 符号,使字符还原为其本来“面目”。如要寻找 $ ($符号在脚本应用中是特殊符号),那么就使用 \$
2、匹配模式表:
[:alnum:] Alphanumeric characters (包括文字和数字等字符)
[:alpha:] Letters (字母)
[:ascii:] ASCII characters (ASCII 字符)
[:blank:] Space or tab (空格或者 tab 键)
[:cntrl:] ASCII control characters (ASCII 控制字符)
[:digit:] Digits (数字)
[:graph:] Noncontrol, nonspace characters (非控制,非空格字符)
[:lower:] Lowercase letters (小写字母)
[:print:] Printable characters (可打印字符)
[:punct:] Punctuation characters (标点字符)
[:space:] Whitespace characters, including vertical tab (空白符,包含垂直 tab)
[:upper:] Uppercase letters (大写字母)
[:xdigit:] Hexadecimal digits (十六进制数字)
示例一:$ grep a[[:blank:]] words2.txt #匹配字母a后面有着空格的行
Is this a dagger which I see before me,
A dagger of the mind, a false creation,
Moves like a ghost. Thou sure and firm-set earth,
$
示例二:$ grep Th.[[:space:]] words2.txt #匹配 Th ,然后再匹配一个任意字符(.),接着匹配空格
The handle toward my hand? Come, let me clutch thee.
The curtain’d sleep; witchcraft celebrates
Thy very stones prate of my whereabout,
$
示例三:$ grep -E [a-z]\{10\} words2.txt #匹配连续有 10 个小写字母的行
proceeding from the heat-oppressed brain?
And such an instrument I was to use.
The curtain’d sleep; witchcraft celebrates
Thy very stones prate of my whereabout,
$ |
|