Concatenate in bash the output of two commands without newline character
I'll try to explain the solution with another simple example
We've to concatenate the output of the following command:
"pwd" and "ls"
echo "$(pwd)$(ls)";
Output: 2 concatenated strings
You can use tr
:
{ echo "The quick"; echo "brown fox"; } | tr "\n" " "
OR using sed:
{ echo "The quick"; echo "brown fox"; } | sed ':a;N;s/\n/ /;ba'
OUTPUT:
The quick brown fox
echo "$(A)" "$(B)"
should work assuming that neither A
nor B
output multiple lines.
$ echo "$(echo "The quick")" "$(echo "brown fox")"
The quick brown fox