Table of contents
1. The cause of ^M
When the text file is copied from windows to Linux and opened with vi, there will be an extra ^M after each line, because on Windows, the end of each line is composed of carriage return (\r) and line feed (\n), expressed as "\r\n". On Linux, the end of each line is just a newline character (\n), represented as "\n".
2. Solutions
Use notepad++ to open the file, click Windows (CR LF) on the lower right foot and change it to Unix.