I go back and forth between windows and linux, and find myself running into problem with line endings. Is there a way to control the line ending conversion when writing files, such as write and cat? More explicitly I want to be able to write files with LF line endings rather than CRLF line ending on windows; and CRLF line endings instead of LF on linux, and I want to be able to control when the conversion is made and/or choose the line endings that I want. As far as I can tell the conversion is not optional and buried deep in compiled code. Is there a possible work around? Thanks, Andrew
Duncan Murdoch
2012-Apr-24 17:48 UTC
[Rd] Write unix format files on windows and vice versa
On 24/04/2012 1:23 PM, Andrew Redd wrote:> I go back and forth between windows and linux, and find myself running > into problem with line endings. Is there a way to control the line > ending conversion when writing files, such as write and cat? More > explicitly I want to be able to write files with LF line endings > rather than CRLF line ending on windows; and CRLF line endings instead > of LF on linux, and I want to be able to control when the conversion > is made and/or choose the line endings that I want. > > As far as I can tell the conversion is not optional and buried deep in > compiled code. Is there a possible work around?On Windows you will write CRLF if the file was opened as a text file, and LF only if it was opened as a binary file. For example: writeLines(letters, "crlf.txt") con <- file("lf.txt", open="wb") writeLines(letters, con) close(con) On Unix you can write CRLF by specifying that as the sep arg. So the following will work on both systems: con <- file("crlf.txt", open="wb") writeLines(letters, con, sep="\r\n") close(con) (and the explicit connection isn't really necessary on Unix, but it is on Windows). If you're not using the writeLines() function, it's probably a bit harder to set CRLF as a default on Unix than it is to set LF as a default on Windows. Duncan Murdoch
(Ted Harding)
2012-Apr-24 17:56 UTC
[Rd] Write unix format files on windows and vice versa
On 24-Apr-2012 17:23:00 Andrew Redd wrote:> I go back and forth between windows and linux, and find myself > running into problem with line endings. Is there a way to > control the line ending conversion when writing files, such as > write and cat? More explicitly I want to be able to write files > with LF line endings rather than CRLF line ending on windows; > and CRLF line endings instead of LF on linux, and I want to be > able to control when the conversion is made and/or choose the > line endings that I want. > > As far as I can tell the conversion is not optional and buried > deep in compiled code. Is there a possible work around? > > Thanks, > AndrewRather than write the Linux version out in Windows (or the other way round in Linux), you might find it more useful to use an external conversion utility. One such is unix2dos/dos2unix (the same program in either case, whose function depends on what name you call it by). This used to be standard on older Linux systems, but may need to be explicitly installed on your system. It seems there may also be a version for Windows -- see: http://download.cnet.com/Unix2DOS/3000-2381_4-10488164.html Then, when you create a file in Windows, you could transfer it to Linux and covert it to "Unix"; and also keep it as it is for use on Windows. Conversely, when you create a file in Linux, you coled convert it to "Windows" and transfer it to Windows; and also keep it as it is for use on Linux. It is also possible to do the CRLF-->LF or LF-->CRLF using 'sed' in Linux. For some further detail see http://en.wikipedia.org/wiki/Unix2dos Hoping this helps, Ted. ------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at wlandres.net> Date: 24-Apr-2012 Time: 18:56:21 This message was sent by XFMail
Possibly Parallel Threads
- Guidelines when to use LF vs CRLF ("\n" vs. "\r\n") on Windows for new lines (line endings)?
- AEL - what is error: ael.flex:647 ael_yylex: Unhandled char(s):
- [PATCH 0/4] firstboot: assorted enhancements
- should dovecot store maildir files with CRLF or LF?
- Problem running Windows Notepad under Wine