DOS saves text files differently to Linux. If you write a text file in Windows and then open in in Linux, you may see a ^M on the end of each line. This is just the way that Windows tells your text editor that the line has finished. It’s the character that is used when you press enter.
To get rid of each ^M in Vi use the following command:
1,$s/^M//g
To get the ^M character don’t type ^ and M! You need to press Ctrl+v and then Ctrl+m
The 1 at the beginning means start at line 1 and the $ means finish on the final line.
s is the search and replace command. It is used in the format of s/string to search for/string that replaces the search string/
The final g is part of the search and replace command. it makes the command global. If you don’t have the g on the end only the first instance is replaced.