[Omaha.pm] LF -> CRLF

Jay Hannah jhannah at omnihotels.com
Mon Mar 14 16:15:13 PST 2005


So we've got a bunch of Unix files that Windows can't read correctly.

   perl -pi -e 's/(?<!\r)\n$/\r\n/' /path/*

All done. Changes every file in /path/*: If the line ends in \n (LF (linefeed)) we change it to \r\n (CRLF (carriage return, line feed)).

Why not just s/\n/\r\n/ ?

Because that would change \r\n to \r\r\n. That would be bad.

Zero-width negative look behind assertions rule.

Grin,

j





More information about the Omaha-pm mailing list