1

I am running an xcodebuild command:

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

This produces lots of un-intesting output which I can filter using something similar to this answer xcodebuild | egrep -A 5 "(error|warning):"

However, I am interested in all of the test output. The test output comes after this line:

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

So Is there a way to grep or filter everything after the above line? Preferable so that the error warning filter is preserved, i.e. Show the line if:

  • Either the line contains "error" or "warning"
  • Or the line is after the 'Test Suite * started at*' line
Community
  • 1
  • 1
Robert
  • 37,670
  • 37
  • 171
  • 213
  • 1
    Check [Print lines in file from the match line until end of file](http://stackoverflow.com/questions/3434462/) – fedorqui Sep 29 '14 at 16:03
  • @fedorqui - This looks good, would I pipe the output to a file and then `sed` it? – Robert Sep 29 '14 at 16:26
  • 1
    You can directly pipe the command to `sed`, as these good answers mention. Note also that some of your output can be `stderr`, in such case you have to [redirect it to `stdin`](http://www.cyberciti.biz/faq/redirecting-stderr-to-stdout/). – fedorqui Sep 30 '14 at 08:14

4 Answers4

4

Another choice:

xcodebuild ... | sed '1,/^Test Suite/d'
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
1

Use awk:

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

Initially, print_me has a false value, so the bare print rule will not be executed. Once a line matching the "Test Suite started" line is seen, the value of print_me switches to a true value, and the print rule will be executed for each line from then on.

chepner
  • 497,756
  • 71
  • 530
  • 681
  • Thank you for your answer! :) I am getting many errors now labeled `stream error: stream error at offset 29: created by an unsupported XCDependencyGraph build`, any ideas? – Robert Sep 29 '14 at 17:30
  • @Robert, those errors have *nothing* to do with this answer. – glenn jackman Sep 29 '14 at 17:54
  • Note that it is not necessary to define `print_me`. The default value of variable in awk is 0 (or null, or whatever), so `print_me {print}` would work. Also, `print_me` alone does the same, because the default behaviour of awk is `{print $0}`. – fedorqui Sep 29 '14 at 18:38
  • I used the explicit `{ print }` action to avoid having to explain the default action, but I missed that I could omit the `-v print_me=0`. – chepner Sep 29 '14 at 18:59
  • @glennjackman - Yes you are right, I think that output was from the `stderr` output. – Robert Sep 30 '14 at 09:59
1
xcodebuild ... | grep -A 999999999 "search string"
Cyrus
  • 84,225
  • 14
  • 89
  • 153
1

Using awk:

xcodebuild ... | awk '/^Test Suite/{test=1; next}test'
John B
  • 3,566
  • 1
  • 16
  • 20