Programming trick: CR and LF

If you ever find yourself in the situation of having to replace CRLF (Win) or CR (Mac) with LF (Unix), remember that the regex/C escape codes are \n=LF and \r=CR (and for good measure, \f = FF).

A sed string that will do the correct replacement is 's/\r\n|\r/\n/g'. On OS X, you can use it in conjunction with pbpaste, which will paste to stdout the content of the OS X clipboard (this hint from macoshints).

Apr 05, 2005

CRLF (/progtricks)
2005-04-05, 13:59 [edit]


  Login:   Password:   [rss] [cc] [w3] [css]

© M. Vallisneri 2012 — last modified on 2010/01/29

Tantum in modicis, quantum in maximis