...except nobody actually has dos2unix, so sed -i 's/\r//' filename will work better (on linux. on other systems you may need to tr -d '\r' < filename > tempname ; cat tempname > filename ; rm tempname )
The issue here is to delete any \r char in the file, since windows uses \r\n and unix only accepts \n, the sed/tr/vi commands tries to acomplish the same effect on the file, to delete the \r char which is presented as a terminator on each line.
If you use editor vim, you may be interested in fileformat. Here's a help excerpt:
*'fileformat'* *'ff'*
'fileformat' 'ff' string (MS-DOS, MS-Windows, OS/2 default: "dos",
Unix default: "unix",
Macintosh default: "mac")
local to buffer
{not in Vi}
This gives the <EOL> of the current buffer, which is used for
reading/writing the buffer from/to a file:
dos <CR> <NL>
unix <NL>
mac <CR>
When "dos" is used, CTRL-Z at the end of a file is ignored.
See |file-formats| and |file-read|.
...