My first question:

How can I tell a web file's code format's line break type?

Is it LF(unix) or is it CR LF (windows)?

My second question:

I have been using LF(unix) code format all the time, and the hosting is unix too. But my clients may have used CR LF(windows) to update some content.

So right now, I don't know in thousands files of the web site. which file is LF(unix) which is CR LF (windows).

Are there any ways to clean this mess up? Like run some command on the unix hosting copy and cover all the file code format to LF(unix)?

By the way, line break type CR LF (windows) file is not an ASCII file right, if they use old ftp and download the CR LF (windows) file in ASCII format, they will have problems? like empty line added etc., right?

    blackhorse wrote:

    How can I tell a web file's code format's line break type?

    Is it LF(unix) or is it CR LF (windows)?

    Search for \r\n at the end of a line; if it's there then it's Windows, if just \n is there then it's Unix, if just \r is there then it's Mac.

    blackhorse wrote:

    Are there any ways to clean this mess up? Like run some command on the unix hosting copy and cover all the file code format to LF(unix)?

    You could probably do this with sed, but it's been so long since I've used it that I've forgotten the syntax. You might try Google'ing for a sed one-liner to change line endings.

    blackhorse wrote:

    By the way, line break type CR LF (windows) file is not an ASCII file right

    Why wouldn't it be? Both CR and LF are ASCII characters (see Ascii Table if you don't believe me), so why would one line ending make the file non-ASCII?

    blackhorse wrote:

    if they use old ftp and download the CR LF (windows) file in ASCII format, they will have problems? like empty line added etc., right?

    I thought most (halfway decent?) FTP editors transformed line endings when files were downloaded in ASCII format and had different line endings than the user's OS used.

    Either way, most text editors out there can automatically detect the line endings anyway, so why does it matter if the file has CRLF or just LF or just CR?

      thanks, my mind slipped here. Yes of course CRLF is ascii.

      But what I am facing is this CRLF ASCII file when ascii download from the unix server, empty line is added for each line.

      OK, here is what happens. I don't know what ftp and what version of dreamweaver the client used. But I tried with an old win ftp to repeat the error, only in this case, the CRLF file get messed up.

      1) file saved as CR LF (windows)
      2) binary ftp upload it to unix server.
      3) ascii ftp download it back to local machine.
      4) the file is messed. it is added with empty line below every line after this process.

      What is the logic behind it?

      A glitch in dreamweaver or old win ftp? or it is supposed to be like that?

      My guess of the logic is

      1) file saved as CR LF (windows) - CR LF for each line return.
      2) binary ftp upload it to unix server. Binary transfer the file as it is, so the CR LF is kept. (if we ascii transfer the CR LF file to unix hosting, it turned to LF file)
      3) ascii ftp download. Due to it is ascii download, the format may not be kept as original. It is reading from a unix server of a file with CR LF, some how, it reads CR LF to two lines.

      I don't know why ftp upload from windows local to unix hosting, doesn't matter the file is CR LF or LF, does matter the ftp mode is ascii or binary, the uploaded file is OK.

      But when ascii download CR LF file from unix server, then the file is added with one empty line for each line.

        Write a Reply...