There are multiple ways to convert file from dos to linux and vice-versa.
I will try to cover most of them in this post
The main reason to convert the file is because windows add control-m at the end of each line, which is problematic in linux because it will be interpreted as a character as the rest of the line and will eventually make some scripts failed.
To see if a file contain control-m all you need to do is :
1- cat –v filename
2- vi filename
To transfer a file without control-m :
Just transfer the file in ascii mode.
Using ‘dos2unix’ and ‘unix2dos’
(the easiest method, if dos2unix is installed on your system)
a. dos2unix filename ---- To remove control-m
b. Unix2dos filename ---- To put back control-m at the end of the line
a. tr –d ‘r’ < file_to_modify > resulting_file
b. tr –d ‘^M’ < file_to_modify > resulting_file
---- To do the ^M , press [ctrl]+v followed by [ctrl]+m
c. in both cases after you need to move back the resulting file into the original file
Using ‘vi’ --- Very easy also , if the file is not too big
a. vi filename --- Position yourself on the first line
b. :%s/^M//g --- Then press enter , and voila !
Please feel free to leave comments, suggestion or to share this post!