dos2unix bash script – part two
In this article I’ll show you a more complex script than the script I have shown in the article dos2unix bash script. This new script allow you to convert more than one file at the same time.
In this article I’ll show you a more complex script than the script I have shown in the article dos2unix bash script. This new script allow you to convert more than one file at the same time.
Vim (vi improved) provides a rapid way to change the format from dos to unix and viceversa.
After you have opened your text file, just type the following command in vim:
:set fileformat=unix
to change the format to unix, or type:
:set fileformat=dos
In this article I will show you a short bash script that will do a dos2unix text file conversion.
1: #!/bin/bash
2: cat $1|tr -d '\015'
After dos2unix using vim, here is dos2unix using sed
in bash you could type the following command:
# sed 's/^M$//' input.txt > output.txt
or you can convert UNIX to DOS by typing the following command:
# sed 's/$'"/`echo \\\r`/" input.txt > output.txt
Often I need to translate source code from dos/windows format to UNIX format, MS-DOS and WINDOWS use a <carriage return>-<line feed> combination to represent end of line char while UNIX uses only a <line feed>.
Latest comments