⇤ ← Revision 1 as of 2007-05-02 23:44:22
Size: 469
Comment:
|
Size: 906
Comment: more methods, hyperlink, and clarify a GNUism
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
== How do I convert a file in DOS format to UNIX format. ( Remove CRLF line terminators ) == | == How do I convert a file from DOS format to UNIX format (remove CRs from CR-LF line terminators)? == |
Line 4: | Line 4: |
All these are from the sed one-liners page | All these are from the [http://www.student.northpark.edu/pemente/sed/sed1line.txt sed one-liners page]: |
Line 8: | Line 8: |
sed 's/\x0D$//' dosfile | sed 's/\x0D$//' dosfile # GNUism - does not work with Unix sed! |
Line 11: | Line 11: |
Some distributions have ''dos2unix'' command which can do this. In vim, you can use '':set fileformat=unix'' | If you want to remove all CRs regardless of whether they are at the end of a line, you can use {{{tr}}}: {{{ tr -d '\r' < dosfile }}} If you want to use the second {{{sed}}} example above, but without embedding a literal CR into your script: {{{ sed $'s/\r$//' dosfile # BASH only }}} Some distributions have a {{{dos2unix}}} command which can do this. In vim, you can use {{{:set fileformat=unix}}} to do it. |
How do I convert a file from DOS format to UNIX format (remove CRs from CR-LF line terminators)?
All these are from the [http://www.student.northpark.edu/pemente/sed/sed1line.txt sed one-liners page]:
sed 's/.$//' dosfile # assumes that all lines end with CR/LF sed 's/^M$//' dosfile # in bash/tcsh, press Ctrl-V then Ctrl-M sed 's/\x0D$//' dosfile # GNUism - does not work with Unix sed!
If you want to remove all CRs regardless of whether they are at the end of a line, you can use tr:
tr -d '\r' < dosfile
If you want to use the second sed example above, but without embedding a literal CR into your script:
sed $'s/\r$//' dosfile # BASH only
Some distributions have a dos2unix command which can do this. In vim, you can use :set fileformat=unix to do it.