今天仔细研究了grep,
例如:文件bookword中
there is a book
there is a book.
there is a book'
there is a book)
there is a 'book
there is a 'book.
there is a (book.
there are some books.
there are some 'books.
there is a handbook.
book
books
handbook
如果只想匹配 book. ,
$ grep -n "[ ]book[.]" bookword
如果想匹配所有的book,
$ grep -n "/<book/>" bookword
这里有几个知识点
1. 精确匹配 /< 和 /> 可以去掉如"handbook" 或者"books"这样的单词
2. [“[{(]可以用在单词前,用于匹配符号+单词这样的组合, 如: grep "[(]book" bookword
there is a (book.
3. []})"?!.,;:'s], 可以用于单词后,用于匹配符号+单词,单词复数 如 grep "book[.]" bookword
there is a book.
there is a 'book.
there is a (book.
there is a handbook.
4. (^|空格) 可以匹配单词在行的开始或者一个空格.
5. (空格|$) 可以匹配单词在行的结尾或者一个空格.