如何使用grep与两个模式? [英] How to use grep with two patterns?

查看:307
本文介绍了如何使用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,
然后我做得更简单。任何包含ax或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 . . .

任何赞赏的建议。

推荐答案

这应该适用于您:

egrep '(^ax|sx$)' usr/dict/words

注意

我找不到任何字词以字典中的 sx 结尾 used

这篇关于如何使用grep与两个模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆