Grep中'word'的含义 [英] The meaning of 'word' in Grep

查看:114
本文介绍了Grep中'word'的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 >符号\<和\>分别匹配
>的空字符串。一个词的开始和结束。

这里是什么意思?



我知道这个词是在-w 中定义的,但这里证明了它在这种情况下有不同的含义:

如果文件'test'包含 hi / 和I grep -w'hi /'test ,我得到一个匹配,
但是如果我 grep'hi / \>'test ,我不会。

解决方案

一个单词的开头是一个单词字符(一个字母,数字或下划线),前面没有另一个单词字符,而单词的末尾是一个单词字符,不是之后是另一个单词字符。一个单词就是一系列单词字符。



原因 hi / \> doesn 't match hi / 是因为 \> 前面有一个非单词字符( / ),因此不能是单词结尾的位置。


In the man page for grep it says that:

> The symbols \< and \> respectively match the empty string at the
> beginning and end of a word.

What is meant here by word?

I know that word is defined in -w, but here is the proof that it has a different meaning in this context:

If file 'test' contains hi/, and I grep -w 'hi/' test, I get a match, but if I grep 'hi/\>' test, I don't.

解决方案

The beginning of a word is a word character (a letter, number, or underscore) that is not preceded by another word character, and the end of a word is a word character that is not followed by another word character. A "word" is then just a series of word characters.

The reason hi/\> doesn't match hi/ is because the \> is preceded by a non-word character (/), and so that can't be the location of an end-of-word.

这篇关于Grep中'word'的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆