mac2unix

paulm on 2004-05-28T14:36:35

A "zero script" hack (-e0) to convert in-place Macs' default line endings of \r to \n.

perl -le0 -015pi mac_file.txt


The order of the -l and -0 is important. -l assigns $\=$/ (output record sep = input record sep) and then the -015 sets input record separator to octal 15, aka dec 13 aka \r. So it's splitting the input on \r and outputting (via -p) with \n.

(I was puzzled for a while trying to squeeze even more characters out of it by wondering why -l0 was behaving differently to -l -0. -l takes a number too! So the 0 was a number not a command option.)

Can any more chars be shaved off?