How can I make sed not append a newline character to an input stream that was missing one? If I can't, what's the quickest way to remove a newline character from a variable?
A code sample was requested in the comments, so here you go. Imagine a .csv file that has no newline at the end. Pipe it into a script.
Then inside that script:
function foobarize() {
sed \
-e "s|foo|bar|g" \
$1
}
INPUT=`tee`
printf "$INPUT" | foobarize
If the input has no newline at the end, foobarize will add a newline to it 100% of the time.