[TxMt] converting mac line endings

Paul McCann paul.mccann at adelaide.edu.au
Thu Apr 13 00:38:30 UTC 2006


Brad Choate wrote:

> 	tr -d '\015' < win.txt > unix.txt  # if you can't find dos2unix
>
> What you have there is unix2dos, adding \r in front of \n for each  
> line.

Eh? Looks pretty much as advertised: the "-d" means delete the  
carriage return. (So a CRLF pair becomes a simple LF.)

It will, of course make a 0 line file out of a classic Mac OS text  
file, so it's not exactly what was asked for. I think that

perl -pi -e 's/\015\012?/\012/g' filename.txt

should do the trick: change any CR, possibly followed by an LF, into  
just an LF. The file is changed "in place", but if you want to have a  
backup of the original just put your desired suffix after the i flag. Eg

perl -pi.bak -e 's/\015\012?/\012/g' filename.txt

The original will be in filename.txt.bak

Cheers,
Paul



More information about the textmate mailing list