Append line break to command output
Use echo
, it will automatically append a newline:
echo "`curl -s "http://myserver.com/api?param=1¶m=2"`" | sudo tee -a /var/log/myserver.log
Alternatively, you could try the -w
option, but I found that it somehow prints funny characters to the console (but not to the file, luckily):
curl -s "http://myserver.com/api?param=1¶m=2" -w "\n" | sudo tee -a /var/log/myserver.log
Simplest is just to append a newline using echo
curl -s "http://myserver.com/api?param=1¶m=2" | sudo tee -a /var/log/myserver.log && echo "" >> /var/log/myserver.log
I use awk 1
for that (where 1
is just something that evaluates to true):
$ printf a|awk 1
a
$ printf a\\n|awk 1
a
$
It should work with gawk, BWK awk / nawk (that comes with OS X), and mawk (that comes with Debian). sed -n p
works with OS X's sed but not with GNU sed.
A Bash-only alternative:
printf %s\\n "$(cat)"
Note that $()
removes all linefeeds from the end, so for example echo $'a\n\n'|printf %s\\n "$(cat)"
only prints one linefeed.
You could also replace printf %s\\n
with echo
, but for example x=-nene;echo "$x"
doesn't print anything in Bash (unless xpg_echo
and POSIX mode are enabled).