How would I parse following output of lein test$ lein testlein test nepleaks-engine.core-testRan 1 tests containing 1 assertions.0 failures, 0 errors.Where I want is get number before failures using bash script.I only know better is grep, $ lein test | grep 'failures' | cut -d' ' -f10 Suggest me the better ways of doing this.
Extract the number of failures from a test report
bash;text processing
There is nothing wrong with the way that you are doing it, provided that failures will only occur on one line of the output. Another option might be to anchor on the fact that the number of failures is always on the 4th line of output. This is very easy with awk:lein test | awk 'NR==4 { print $1 }'Or to anchor on a line where failures, is the second field:lein test | awk '$2==failures, { print $1 }'Or to anchor on the last line:lein test | awk 'END { print $1 }'Or using sed to anchor on the last line:lein test | sed -n '$ s/^\([0-9]*\).*/\1/p'