grep '\<hi\>' coco.txt
和之间有什么区别grep 'hi' coco.txt
?我在终端中应用了这些命令,但是看不到任何区别。
在grep
,\<
代表字的开头和\>
代表字的结束。
来自man grep
:
The Backslash Character and Special Expressions
The symbols \< and \> respectively match the empty string at the
beginning and end of a word. The symbol \b matches the empty string at
the edge of a word, and \B matches the empty string provided it's not
at the edge of a word. The symbol \w is a synonym for [_[:alnum:]] and
\W is a synonym for [^_[:alnum:]].
因此,grep '\<hi\>'
将匹配包含单词的任何行hi
,grep 'hi'
并将匹配包含字符序列的任何行hi
:
$ grep '\<hi\>' <<< "hi"
hi
$ grep '\<hi\>' <<< "chimes"
$ # no output since no match
$ grep '\<hi\>' <<< "hi-fi"
hi-fi
$ grep '\<hi\>' <<< "high voltage"
$ # no output since no match
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句