使用sed删除包含特定单词的段落

时间:2015-11-02 11:21:52

标签: linux bash command-line sed terminal

我需要使用sed命令删除包含'foobar'的函数, 也许使用另一个默认命令。我会将它应用于很多文件。

main {
  engine "map" {
    func {
      var0 = foo
      border = { 1, 1, 1, 1 }
      var1 = bar
    }
  }

  engine "map" {
    func {
      var0 = foo
      border = { 1, 2, 1, 2 }
      var1 = foobar
    }
  }

  engine "map" {
    func {
      var0 = foo
      border = { 3, 3, 1, 1 }
      var1 = bar
    }
  }
}

提前谢谢你......

2 个答案:

答案 0 :(得分:0)

您可以RS使用null awk -v RS= -v ORS='\n\n' '!/foobar/' file main { engine "map" { func { var0 = foo border = { 1, 1, 1, 1 } var1 = bar } } engine "map" { func { var0 = foo border = { 3, 3, 1, 1 } var1 = bar } } }

<configuration>
<appender name="FILE_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${application.home}/logs/debug_log.log</file>
    <encoder>
        <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>DEBUG</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${application.home}/logs/debug_log.%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>30</maxHistory>
    </rollingPolicy>
</appender>

<appender name="FILE_WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${application.home}/logs/warn_log.log</file>
    <encoder>
        <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>WARN</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${application.home}/logs/warn_log.%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>60</maxHistory>
    </rollingPolicy>
</appender>

<logger name="play" level="INFO"/>
<logger name="application" level="INFO" />

<root level="WARN">
    <appender-ref ref="FILE_DEBUG"/>
    <appender-ref ref="FILE_WARN"/>
</root>
</configuration>

答案 1 :(得分:0)

您可以类似地使用Perl:

perl -ne 'BEGIN{$/=""} print unless /foobar/' file

$/是perl的记录分隔符。将其设置为""可启用段落模式。