首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在grep中使用指定的量词检索满意的词汇表

在grep中使用指定的量词检索满意的词汇表
EN

Unix & Linux用户
提问于 2018-03-27 06:53:29
回答 1查看 153关注 0票数 1

我试着从一个文件中抓取单词:

代码语言:javascript
复制
$ grep -o '\*\*[^*]*\*\*' Principles_20_LifePrinciples.md | grep -v -e "Origin" -e "Etymology"
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**
**the state of feeling nervous or worried that sth bad is going to happen**
**a worry or fear about sth**
**a strong feeling of wanting to do sth or of wanting sth to happen**

结果,我只想说出一句话:

代码语言:javascript
复制
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**

具有指定的量化符{,20}的重构代码:

代码语言:javascript
复制
$ grep -E -o '\*\*[^*]{,20}\*\*' Principles_20_LifePrinciples.md

不幸的是,它什么也没回。

如何解决这样的问题?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-03-27 07:02:13

对于BSD,有关支持的正则表达式的详细信息,请参阅man 7 re_format。它特别指出:

代码语言:javascript
复制
 A bound is `{' followed by an unsigned decimal integer, possibly followed
 by `,' possibly followed by another unsigned decimal integer, always fol-
 lowed by `}'.  The integers must lie between 0 and RE_DUP_MAX (255=)
 inclusive, and if there are two of them, the first may not exceed the
 second.

只有第二个数字可以省略;第一个数字必须给出。

有了这个解决办法:

代码语言:javascript
复制
$ /usr/bin/grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ /usr/bin/grep -Eo '\*\*[^*]{0,20}\*\*' foo
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**
票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/433748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档