grep字符串,其中part与条件1匹配,但另一部分与条件2不匹配

时间:2016-06-03 07:23:35

标签: grep

在像以下文件中:

build.gradle
dependencies {
    runtime module("org.codehaus.groovy:groovy:2.4.4") {
        dependency("commons-cli:commons-cli:1.0") {
            transitive = false
        }
        module(group: 'org.apache.ant', name: 'ant', version: '1.9.6') {
            dependencies "org.apache.ant:ant-launcher:1.9.6@jar",
                         "org.apache.ant:ant-junit:1.9.6"
        }
    }
}

我如何grep包含oneA twoA threeA oneB twoB threeB oneC threeC oneA twoD threeA 但未跟two的所有行?

A

2 个答案:

答案 0 :(得分:0)

#grep line containing two and exclude which has twoA
grep two filename.txt |grep -v twoA
oneB twoB threeB
oneA twoD threeA

使用Awk:

  awk '!/twoA/ && /two/' filename.txt
  oneB twoB threeB
  oneA twoD threeA

答案 1 :(得分:0)

请说:

$ grep 'two[^A]' file
oneB twoB threeB
oneA twoD threeA

grep two后跟A以外的任何字符。

相关问题