This question is directly related to another question I asked here.
Linux/Unix have nice utilities dos2unix
and unix2dos
for conversion of text files between the two OSs. Are there similar utilities for Macs and Linux?
This question is directly related to another question I asked here.
Linux/Unix have nice utilities dos2unix
and unix2dos
for conversion of text files between the two OSs. Are there similar utilities for Macs and Linux?
I don't know what dos2unix
and unix2dos
do exactly, but my guess is that it changes text file line endings from dos format to Unix format and back. Macs (as of OS X) and Unix use the same line-endings (line-feed, '\n') so if that's what you're worrying about, you don't need to do anything to move files back and forth.
Using dos2unix -c Mac mac_file
turns the Mac formatted file into a Unix formatted file.
-c mac
is correct. I think that's a holdover from the 80's and 90's when classic Mac OS (System 1 through Mac OS 9) text files had bare CRs (carriage returns) as line endings). Mac OS X uses Unix line endings (bare LFs; linefeeds).
\n
. In many contexts, it's technically a "newline" which means that it will be replaced with the correct OS-dependent line ending sequence. So on Mac OS X and other Unixes, it will be replaced with an ASCII LF (linefeed) character 0x0a, but on Windows it may be replaced with a CRLF (0x0d0a). Back in classic Mac OS (Mac OS 9 and earlier), the \n
sequence in MacPerl would be replaced by classic Mac OS's CR (just an ASCII 0x0d carriage return) line ending.
<CR>
and replaced it with an <LF>
character. For a regular Windows file <CR><LF>
, it stripped only the <CR>
.
Commented
Dec 11, 2013 at 20:08
-c Mac
, Thank you. That's what I had to do to make it work.
Commented
Dec 13, 2013 at 19:32
OS X uses LF line endings and UTF-8-encoded files without a BOM in most places like other Unix platforms. CR line endings were mainly used in Mac OS 9 and earlier.
For example AppleScripts and text copied from some views in Finder and iTunes still use CR line endings. You can convert CR line endings to LF with mac2unix
, dos2unix -c mac
, or tr \\r \\n
. dos2unix
and mac2unix
can be installed with brew install dos2unix
.
If you need to convert Windows files to the format used by OS X, you can use dos2unix
. It converts CRLF line endings to LF. If a file is encoded as UTF-16, it also converts the file to UTF-8, and if a file has a BOM, it removes it.