【问题标题】:How do I ignore all output of a bash command until a given marker如何在给定标记之前忽略 bash 命令的所有输出
【发布时间】:2014-09-29 15:59:00
【问题描述】:

我正在运行xcodebuild 命令:

xcodebuild -workspace MyWorkspace.xcworkspace \
           -scheme "$XCODE_SCHEME_NAME" \
           -archivePath $ARCHIVE_PATH \
           -destination "$TEST_DESTINATION_DEVICE" \
           test

这会产生大量未经测试的输出,我可以使用类似于 this answer xcodebuild | egrep -A 5 "(error|warning):" 的内容进行过滤

但是,我对 所有 的测试输出感兴趣。测试输出在这一行之后:

Test Suite 'All tests' started at 2014-09-29 14:04:54 +0000

那么有没有办法 grep 或过滤上述行之后的所有内容?最好保留错误警告过滤器,即在以下情况下显示该行:

  • 该行包含“错误”或“警告”
  • 或该行位于'Test Suite * started at*' 行之后

【问题讨论】:

标签: xcode bash shell xcodebuild


【解决方案1】:

另一种选择:

xcodebuild ... | sed '1,/^Test Suite/d'

【讨论】:

    【解决方案2】:

    使用awk:

    xcodebuild ... | awk -v print_me=0 '/^Test Suite/ { print_me=1 }; print_me { print };'
    

    最初,print_me 的值为 false,因此不会执行裸露的 print 规则。一旦看到与“Test Suite started”行匹配的行,print_me 的值将切换为 true 值,并且此后将为每一行执行 print 规则。

    【讨论】:

    • 感谢您的回答! :) 我收到很多错误,现在标记为 stream error: stream error at offset 29: created by an unsupported XCDependencyGraph build,有什么想法吗?
    • @Robert,这些错误与此答案无关。
    • 请注意,不必定义print_me。 awk 中变量的默认值为 0(或 null,或其他),因此 print_me {print} 可以工作。另外,print_me 单独做同样的事情,因为 awk 的默认行为是 {print $0}。
    • 我使用了显式的{ print } 操作来避免解释默认操作,但我错过了我可以省略-v print_me=0。
    • @glennjackman - 是的,你是对的,我认为输出来自 stderr 输出。
    【解决方案3】:
    xcodebuild ... | grep -A 999999999 "search string"
    

    【讨论】:

      【解决方案4】:

      使用awk:

      xcodebuild ... | awk '/^Test Suite/{test=1; next}test'
      

      【讨论】:

        猜你喜欢
        • 2011-08-21
        • 2022-01-25
        • 2010-10-20
        • 1970-01-01
        • 2020-12-30
        • 2016-04-21
        • 2016-01-27
        相关资源
        最近更新 更多