相关疑难解决方法(0)

Grep 单词边界

根据 GNU 文档:

‘\<’ Match the empty string at the beginning of word.
‘\>’ Match the empty string at the end of word.
Run Code Online (Sandbox Code Playgroud)

我的 /etc/fstab 看起来像这样:

/dev/sdb1       /media/fresh      ext2   defaults     0 0
Run Code Online (Sandbox Code Playgroud)

我希望 grep 为 /media/fresh 的存在返回 TRUE/FALSE。我尝试使用\<\>但没有用。为什么?

egrep '\</media/fresh\>' /etc/fstab
Run Code Online (Sandbox Code Playgroud)

解决方法:

egrep '[[:blank:]]/media/fresh[[:blank:]]' /etc/fstab
Run Code Online (Sandbox Code Playgroud)

但它看起来更丑。

我的 grep 是 2.5.1

grep regular-expression

32
推荐指数
1
解决办法
3万
查看次数

标签 统计

grep ×1

regular-expression ×1