16-05-2024 syam | It happens when file has been transferred between windows systems to unix/linux. New line character is different in both of these systemms. For example, Windows-based text editors will have a special carriage return character (CR+LF) at the end of lines to denote a line return or newline, which will be displayed incorrectly in Unix (^M). This can be difficult to spot, as some applications or programs may handle the foreign newline characters properly while others do not. This typically occurs when a file is transferred from MS-DOS (or MS-Windows) without ASCII or text mode.
Solution :
Notepad ++ or other text editor has ability to select the file type. select Unix for the same, in notepad++, its there in the status bar righthand side.
use unix utility
1. dos2unix filename
2. sed -e "s/\r//g" file > newfile
3. Using a terminal editor vi or vim:
Inside vi [in ESC mode] type: :%s/^M//g
Note: To enter ^M, type CTRL-V + M. That is, hold down the CTRL key then press V and M in succession. |