The dollar sign is just the unix newline character.
Unix line ending format = the ascii
line feed (LF, octal 012) character. Also called "newline".
cat displays it as "
$", and shell notation is "
\n".
DOS line ending format = ascii
carriage return plus
line feed (CR+LF, octal 015+012).
cat displays the CR with the caret notation "
^M", and the shell notation is "
\r"
So when your input has dos style line-endings, tools like
sed and
awk see (and remove) only the LF as the line delimiter, and the CR gets left behind at the end of the line, unseen but capable of causing all kinds of errors.
BTW, old style apple systems used to use CR only as the newline. But since OSX is unix-based, they now use LF too.
BTW2, caret notation is explained here,
http://en.wikipedia.org/wiki/Caret_notation, (and see
man ascii for reference). In a nutshell, add 100 to the non-printing character's octal value to get the character used to display it.