我试着从一个文件中获取单词:
$ 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**结果,我只想说出一句话:
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**具有指定量词{,20}的重构代码:
$ grep -E -o '\*\*[^*]{,20}\*\*' Principles_20_LifePrinciples.md不幸的是,它什么也没回。
如何解决这样的问题?
发布于 2018-03-27 05:51:05
请注意,grep支持\w来匹配单词字符(字母表、数字和下划线),因此您可以很容易地匹配星号之间的部分中的单词字符:
grep -o '\*\*\w*\*\*'发布于 2018-03-27 05:47:20
使用您的第一个grep命令,您就快到了。
如果您只需要匹配只有一个单词的行,那么在[^...]正则表达式中添加一个空格:
$ grep -o '\*\*[^* ]*\*\*' file
**circumstance**
**case**
**condition**
**Anxiety**
**anxiety**https://askubuntu.com/questions/1019528
复制相似问题