Bash concatenate output of two commands into one line

Posted by Dark Training on August 22, 2011 tags: | bash | linux

I recently wanted to have a single line for a command that was running two functions:

for i in `(ls -l |awk '{print $9}')`; do echo $i; cat $i|grep failure|wc -l; done

This gave and output like:

file1
0
file2
0
file3
1

But I wanted:

file1 0
file2 0
file3 1

The trick, use the -n function on echo like this:

for i in `(ls -l |awk '{print $9}')`; do echo -n "$i  "; cat $i|grep failure|wc -l; done