Remove final newline
We can use head with the -c or --bytes flag to remove a number of bytes from the end.
-c, --bytes=[-]NUM print the first NUM bytes of each file; with the leading '-', print all but the last NUM bytes of each file
So, if we want to remove a single newline from the input (or any character for that matter):
$ echo "stuff" | head -c -1Last updated
Was this helpful?