System Administration

Re: Get out of previuos command (N strings) and print it as one string

 
SOLVED
Go to solution
Maxim Yakimenko
Super Advisor

Get out of previuos command (N strings) and print it as one string

Hi, collegues

How do I take out stream of command and print it out as one string. For example out is

1
2
3

and I want to print it as
1 2 3
5 REPLIES 5
J. Bravo
Respected Contributor
Solution

Re: Get out of previuos command (N strings) and print it as one string

Hi!

Try with xargs. For example:

ls | xargs

puts the output in one line.

Regards;

J. Bravo.
Dennis Handly
Acclaimed Contributor

Re: Get out of previuos command (N strings) and print it as one string

It depends on the commands. You could do something like this:
echo $(echo a
echo b
echo c )

Or send the output to a file, then:
(echo a
echo b
echo c ) > outfile
echo $(< outfile)
Sandman!
Honored Contributor

Re: Get out of previuos command (N strings) and print it as one string

# xargs < file
Peter Nikitka
Honored Contributor

Re: Get out of previuos command (N strings) and print it as one string

Hi,
solution with 'tr' (2nd arg is quote-blank-quote):
ls | tr '\012' ' '

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Arturo Galbiati
Esteemed Contributor

Re: Get out of previuos command (N strings) and print it as one string

Hi,
echo $(your command)

HTH,
Art