如何使用grep有两种模式? [英] How to use grep with two patterns?
本文介绍了如何使用grep有两种模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我按照很多链接和参考文档,但仍然面临着错误。
我想列出所有的字开始或SX结尾。
我已经找到工作正常的解决方案:
I have followed many links and reference documentation but still facing errors. I want to list all the words start or ending with 'sx'. I already found a solution which works fine:
awk '/^sx|sx$/' usr/dict/words
不过,我试图用grep或者egrep的和既不工作。
然后,我把它简单。其中包含斧头或SX,并再次没有工作的任何一句话!
However I tried to use grep or egrep and neither worked. And then I made it simpler. Any word which contains 'ax' or 'sx', and again it did not work!
grep 'ax|sx' words
grep -E '^ax\|sx$' words
egrep '^ax\|sx$' words
错误:
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
任何建议AP preciated。
Any suggestion appreciated.
推荐答案
这应该为你工作:
egrep '(^ax|sx$)' usr/dict/words
注意:结果
我找不到在字典我已经的 SX 结尾的单词接口/例子/ dictionary.txt相对=nofollow>使用。
NOTE:
I couldn't find any words ending in sx
on the dictionary I've used.
这篇关于如何使用grep有两种模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文