Sometimes you might find a lot of ^M appended to every line in vim editor on unix/Linux
This is appended because there is a difference between how Windows and a Unix OS implement the end-of-line character.
In Windows, an end-of-line is implemented by a pair of characters - 0x0D0A (carriage return (0x0D) + line feed(0x0A)).
While, Unix-based machines only use 0x0A (a line feed).
The ^M that you are seeing is a text representation of 0x0D (a carriage return).
There are multiple ways to remove these ^M characters:
In Vim Editor
Do not use shift+6 to type the ^ character, ^M is just one character not two, So to type ^M in vim type "Ctrl-v and press Enter"),
Using dos2unix utility command
To convert the file and copy the converted file into another files
dos2unix yourfilename filename2
To convert the file in-place.
dos2unix -o filename