我试着从一个文件中抓取单词:
$ 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**我打算的结果是:
# only words
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**具有指定量化符{,20}的重构代码
$ grep -o '\*\*[^*]{,20}\*\*' Principles_20_LifePrinciples.md不幸的是,它没有返回任何信息。
如何解决这样的问题?
发布于 2018-03-27 01:45:01
您可以添加-E标志:
$ grep -E -o '\*\*[^*]{,20}\*\*' input | grep -v -e "Origin" -e "Etymology"
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**您还可以只匹配只包含alpha字符的文本:
$ grep -o '\*\*[[:alpha:]]*\*\*' input对于input,我使用了您的原始输出。
发布于 2018-03-27 06:29:09
既然你已经
grep -o '\*\*[^*]*\*\*' Principles_20_LifePrinciples.md在[^*]*中添加一个空格(即[^* ]*。
发布于 2018-04-03 16:30:08
请注意
{ start,end},不应省略开始限定符。
$ grep -E -o '\*\*[^*]{0,20}\*\*' input | grep -v -e "Origin" -e
"Etymology"
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**https://stackoverflow.com/questions/49503099
复制相似问题