This is useful when you do not have dos2unix command.
You can determine whether a file is having DOS End of Line.
$ od -c dos_file.txt | grep "\\\r" | wc -lIf you see any output other than 0, then this file
is having \r\n as new line (i.e DOS EOL).
1. Suppose you want to convert EOL of dos_file.txt . Open this
file using vim as:
$ vim dos_file.txt2. If ^M (Ctrl-M) character is at end of every line, then this file
is in DOS format. We have to remove this ^M from the end
of line. Therefore, go to Edit mode by pressing Esc (Escape
button).
3. Type
:%s/^M$//gAnd viola!, you will find that all ^M has gone from end of line.
4. Now, save the file and exit.
PS. In order to type ^M on screen, you should press Ctrl-v Ctrl-mOtherwise this method will not work.Alternatively, you can use sed to remove ^M from end of line, given
as following:
$ sed 's/^M$//g' dos_file.txt > temp$ mv temp dos_file.txt