Linux (commonly pronounced LIH-N?ks in English; variants exist) is a Unix-like computer operating system. Linux is one of the most prominent examples of free software and open source development: typically all underlying source code can be freely modified, used, and redistributed by anyone.
Tags | linux | bash
Bash concatenate output of two commands into one line
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
Comments
Feel free to leave a comment or question