使用sed/awk打印具有匹配模式或其他匹配模式的行 [英] Using sed/awk to print lines with matching pattern OR another matching pattern
本文介绍了使用sed/awk打印具有匹配模式或其他匹配模式的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 sed .我觉得这很容易,但是似乎找不到答案.有什么想法吗?
I need to print lines in a file matching a pattern OR a different pattern using awk or sed. I feel like this is an easy task but I can't seem to find an answer. Any ideas?
推荐答案
POSIX方式
awk '/pattern1/ || /pattern2/{print}'
编辑
说句公道话,我更喜欢通过/pattern1|pattern2/
使用 lhf 的方式,因为对于相同的结果,它需要更少的键入操作.但是,我要指出,此模板不能用于逻辑AND 操作,因为您需要使用我的模板,即/pattern1/ && /pattern2/
Edit
To be fair, I like lhf's way better via /pattern1|pattern2/
since it requires less typing for the same outcome. However, I should point out that this template cannot be used for logical AND operations, for that you need to use my template which is /pattern1/ && /pattern2/
这篇关于使用sed/awk打印具有匹配模式或其他匹配模式的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文