As Jonathan Leffler points out, you don't want the grep
. The command you're using:
./script | grep tr "\n" " "
doesn't even invoke the tr
command; it should search for the pattern "tr"
in files named "\n"
and " "
. Since that's not the output you reported, I suspect you've mistyped the command you're using.
You can do this:
./script | tr '\n' ' '
but (a) it joins all its input into a single line, and (b) it doesn't append a newline to the end of the line. Typically that means your shell prompt will be printed at the end of the line of output.
If you want everything on one line, you can do this:
./script | tr '\n' ' ' ; echo ''
Or, if you want the output wrapped to a reasonable width:
./script | fmt
The fmt
command has a number of options to control things like the maximum line length; read its documentation (man fmt
or info fmt
) for details.