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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityJust 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
Feed it through some utility which read input in lines and output lines, like in awk { print $0 }
.