Unix grep命令试图在故事中找到一个特殊词

时间:2017-02-16 07:25:38

标签: unix grep

我试图在一个故事中找到一个特定的单词“und”但是在这个单词之后它不能有e,这是一个例子:

Under the rope she went. Going under the rope she ran towards the abandoned 
house and and went around it to find her sister.
 She bound over a fallen tree while running around the house, and it was there she found her sister. 
She now understood where her sister had been going all this time. 
It was not until now, every time her sister went missing for a few hours, she never knew where she went.

使用grep命令我需要找到单词:around,bound和found,但不能:理解,under,round等。 我试过了:

grep 'und' story.txt | grep -v 'unde'

但是出于某些原因,从这段代码的第一部分开始,我最终也会突出显示“直到”这个词,但是我需要它来“und”而不仅仅是“un”,任何建议吗? / p>

1 个答案:

答案 0 :(得分:0)

这个怎么样?

grep -oi '[^ ]*und\>' file

输出:

$ grep -oi '[^ ]*und\>' file
around
bound
around
found