2017-02-16 87 views
0

我想一个故事“UND”找到一个特定的词,但这个词后,它不能有E中的上特有的字,下面是一个例子:Unix的grep命令试图寻找故事

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命令,我需要找到的话:周围,约束,和发现,而不是:明白,下,圆形等 我曾尝试:

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

但是从这个第一部分因故代码我会最终与它同时突出显示单词“直到”,但我需要它有“und”不只是“联合国”,任何建议?

+0

你需要提取这些词或干脆让这些话线? – Sundeep

+0

'grep -w'和'story.txt'怎么样?或者'grep'和[^ e]'story.txt'? – ghoti

+1

'grep'und'story.txt | grep -v'unde''实际上应该工作...并且不应该匹配像'until'之类的词......其他的东西似乎有问题 – Sundeep

回答

0

这个呢?

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

输出:

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