13

I have some command which produces output with no new line at the end, like this

Myprompt$ somecmd
dksfjdl
dsfjdlkfj
dsfjdkfj
dfjdkfjMyprompt$

Currently I overcome this by somecmd | sed 's/$/\n/' | tr -s '\n' Is there a better way to do this?

2 Answers 2

20

Just run echo after it, it should generate a newline

Myprompt$ somecmd ; echo

And If you need to feed it to something else, run it in a sub-shell:

Myprompt$ ( somecmd ; echo ) | someothercmd

Or.. as @camh points out, the subshell is actually not needed you can execute it with a command list in the current shell environment with:

Myprompt$ { somecmd ; echo ; } | someothercmd
0
3

Feed it through some utility which read input in lines and output lines, like in awk { print $0 }.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .