11

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?

19

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
| improve this answer | |
3

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.