I have set of windows files and unix files. I want to convert all those files into mac files file format.

Any help would be appreciable.

link|improve this question

67% accept rate
I think you need to be more specific about what type of files you have. Are you trying to do this programmatically or just in your OS shell? – Guy Nov 16 '10 at 15:16
Do you want to do it on mac or on unix? – andcoz Nov 16 '10 at 15:20
I have hundreds of .c/.h files. I want to convert all those files to mac os format. I am ok with either ways, but my ultimate goal is to convert all those files to mac file format. – Thangaraj Nov 16 '10 at 15:21
it would be good if it is in mac. – Thangaraj Nov 16 '10 at 15:22
2  
Search for 'dos2unix' on superuser.com. Voting to migrate. (And by the way, MacOSX systems don't use a different format than unix... you'd have to go back many years in Macintosh operating systems to find a time when they used a different format than MS/DOS and UNIX.) – Ether Nov 16 '10 at 15:43
show 1 more comment
feedback

migrated from stackoverflow.com Nov 17 '10 at 0:53

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 1 down vote accepted

The question doesn't explicitly say, but I assume you mean text files, and need to convert the line delimiter format? OS X doesn't ship with command-line file converter tools, you have to build them yourself. Perl is good for Q&D utilities like this:

perl -pe 'if (s/\r?\n/\r/g) {$f=1}; if ($f&&eof()) {s/\r\z//}' PCfile.txt >Macfile.txt

or, to convert in place:

perl -pe 'if (s/\r?\n/\r/g) {$f=1}; if ($f&&eof()) {s/\r\z//}' -i convertfile.txt

Note: this script is a little more complicated than it probably needs to be, because it's written to work on on both PC-format (CRLF line terminators) and unix files (LF terminators), and leave files that're already in the old traditional MacOS format (CR separators between lines) alone. Also, the PC and unix formats put a terminator after the last line, while Mac format doesn't (it uses line separators, not terminators), so this script detects when it's actually translating, and removes the last delimiter.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.