Symphonious

Living in a state of accord.

Combining Output of Multiple Bash Commands Into One Line

I wanted to create a CSV file showing the number of JUnit tests in our codebase vs the number of Spock tests over time. I can count the number of tests, along with the revision pretty easily with:

git svn find-rev HEAD
find src/test -name '*Test.java' | wc -l
find src/test -name '*Spec.groovy' | wc -l

But that outputs the results on three separate lines and I really want them on one line with some separator (comma, space or tab). The simplest way to achieve that is:

echo "$(git svn find-rev HEAD), $(find src/test -name '*Test.java' | wc -l), $(find src/test -name '*Spec.groovy' | wc -l)"

It’s also very handy to remember that echo has a -n option which omits the trailing new line, so:

echo -n 'Revision: ' && git svn find-rev HEAD

outputs:

Revision: 55450
  • Adrian Sutton says:

    And obviously to go back through time, I just use a bash for loop:
    for i in {1..500}; do spockvjunit >> ~/spock.csv && git checkout HEAD^; done

    May 13, 2014 at 12:57 am
  • Dalibor says:

    And what is the trend?

    May 13, 2014 at 7:20 am
  • Adrian Sutton says:

    Very slow increase in percentage of tests being used in Spock but both types of tests increasing in number at almost the same rate. Not sure what to make of the numbers at this stage.

    May 13, 2014 at 12:00 pm

Your email address will not be published. Required fields are marked *

*