Carriage Return control character (^M) found in wp-config-sample.php

Unix and Unix-like operating systems (like Linux) use different line endings in their text files.

The format of Windows and Unix text files differs slightly. In Windows, lines end with both the line feed and carriage return ASCII characters, but Unix uses only a line feed. As a consequence, some Windows applications will not show the line breaks in Unix-format files. Likewise, Unix programs may display the carriage returns in Windows text files with Ctrl-m (^M) characters at the end of each line.

—From Convert between Unix and Windows text files

Presumably you’ve copied a file that was created on Windows to a Linux machine, and so you’re seeing the Windows line endings when you edit the file on Linux.

The solution provided in your wordpress.org support post — use dos2unix — will clean it up.

I can’t say precisely why your question was downvoted, as I’m not the downvoter, but if I had to guess I’d say it was because this is a Windows / Linux question, not a specifically WordPress-related question. (Yes, it’s a WordPress file, but it’s not really related to WordPress development at all.)