如何使用grep来匹配同一行中的多个字符串? [英] How to use grep to match multiple strings in the same line?
本文介绍了如何使用grep来匹配同一行中的多个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用 grep
来匹配包含两个不同字符串的行。我尝试了以下方法,但它匹配包含 string1 或 string2 的行,这些行不是我想要的。
I am trying to use grep
to match lines that contain two different strings. I have tried the following but this matches lines that contain either string1 or string2 which not what I want.
grep 'string1\|string2' filename
那么,如何与 grep
只匹配包含两个字符串的行?
So how do I match with grep
only the lines that contain both strings?
推荐答案
您可以使用 grep'string1'filename | grep'string2'
或者 grep'string1。* string2 \ | string2。* string1'filename
这篇关于如何使用grep来匹配同一行中的多个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文