DOS/Unix line break/ending/terminator settings

DOS/Unix line break/ending/terminator settings

2
NewbieNewbie
2

    Feb 07, 2006#1

    I need some help setting up UltraEdit. This is basic, but so am I :-)

    I normally would create Perl programs in Notepad and then FTP them (WS FTP) as ASCII to my Linux server.

    Here is my issue:
    I create a new file (Perl script) in UltraEdit or copy code from another text file and paste into UltraEdit.

    I FTP the file (ASCII) to my server.

    I can run the Perl script from the command line on my Linux server but the program will not run via the browser.

    I have figured out that it is something to do with the way UE is adding LF and or CR at the end of lines.

    If I retype the code (not copy but type out) into notepad and upload to my server it runs fine.

    How do I setup UE so that I do not run into this problem or even better, if I open a file in UE how can I get UE to save in the right format so that when I FTP the Perl program up to my server it will run properly.

    I have stopped using UE due to this issue, so I would appreciate any help!

    6,606548
    Grand MasterGrand Master
    6,606548

      Feb 08, 2006#2

      Most content servers are Linux servers. So text files must (should) have Unix line endings which is LF only. Default for MS OSes (DOS) is CRLF as line ending. If you FTP a file with ASCII, the FTP client modifies your file during upload by replacing all CRLF by LF (delete CR) and during a download replace all LF with CRLF (add CR).

      What format the file currently open in UltraEdit has is shown in the status bar at bottom of the UltraEdit window (DOS, Unix, UTF-8, ...). You have 2 possibilities now:

      1) You always create, save and edit DOS files and upload/download it via FTP with ASCII mode (CRLF conversion).

      2) You create and save your files with Unix line ending but for better interchange with other windows applications like Notepad the Unix files are temporarily converted by UltraEdit to DOS during editing only. The Unix files must be uploaded/downloaded with binary FTP transfer, not ASCII.


      For 1) set following in UltraEdit in the Advanced - Configuration - File Handling dialog:

      Conversions - activate On Paste convert line ending to destination type (UNIX/MAC/DOS).

      DOS/UNIX/MAC Handling - set Default file type for new files to DOS and Unix/Mac file detection/conversion to Automatically convert to DOS format.

      Save - turn off Save file as input format (UNIX/MAC/DOS).

      And last on File - Save As - make sure that Line Terminator is set to Default or DOS Terminators and Format to Default or ANSI/ASCII because these settings are automatically used on every save of a new file until changed again.


      For 2) set following in UltraEdit in the Advanced - Configuration - File Handling dialog:

      Conversions - activate On Paste convert line ending to destination type (UNIX/MAC/DOS).

      DOS/UNIX/MAC Handling - set Default file type for new files to UNIX and Unix/Mac file detection/conversion to Automatically convert to DOS format.

      Save - turn on Save file as input format (UNIX/MAC/DOS).

      And last on File - Save As - make sure that Line Terminator is set to Default or UNIX Terminators and Format to Default or ANSI/ASCII.


      And check if your files do not have already invalid line endings like a CRCRLF or LFCRLF sequence. CRCRLF can be easily found with ^r^r^n and replaced by ^p. To find and replace an invalid LFCRLF sequence you need a regular expression replace in UltraEdit style searching for ^([~^r]^)^n^r^n which is replaced by ^1^p.

      2
      NewbieNewbie
      2

        Feb 08, 2006#3

        Wow! Thanks! This spells it all out.

        P

        1
        NewbieNewbie
        1

          Jul 26, 2009#4

          I have the following options set:

          * DOS as default
          * Detect and Prompt
          * Save file as input format

          and I have a one line bash script file. I save it as UTF-8 NO BOM, with Unix line termination. I look at my file in HEX mode I see 0D 0A at the end. I select the entire file, choose DOS>UNIX conversion, the 0D 0A are still there. I remove the newline characters then add them manually, 0D 0A still there. I save it again as UTF-8 NO BOM, with Unix line termination and when I reopen, I choose "NO, I don't want to convert to DOS", 0D 0A still there.

          This is driving me nuts. What is going on?

          6,606548
          Grand MasterGrand Master
          6,606548

            Jul 27, 2009#5

            When you create a new file it is created with DOS line endings according to your settings. You are also working with temporary files. The DOS line endings remain even after saving the new file with UNIX line endings or when converting manually from DOS to UNIX in the temporary file. When you switch to hex edit mode you see the temporary file. So you always see 0D 0A even after saving with UNIX line endings or after conversion to UNIX. But the real file is nevertheless saved with UNIX line endings (0A only). The prompt you get after closing the file and re-opening it shows you that the file was really saved with UNIX line endings. But when working with temporary files and you open the hex edit view you see again 0D 0A because in the temporary file DOS line endings are used.

            I work also with DOS as well with UNIX line endings. Therefore I have chosen Automatically convert to DOS format and use Save file as input format (UNIX/MAC/DOS). With that settings the UNIX files are converted to DOS for editing only (which of course takes place automatically when working with temporary files), but nevertheless saved as UNIX files. Big advantage with that settings is that lines copied via clipboard to other programs are copied with 0D 0A as normal for Windows and not sometimes with 0D 0A and sometimes with 0A only depending on the format of the line endings of the current file. Also always working (temporarily) with DOS line endings makes macros, scripts and find/replaces with line endings much easier because I know, all files have DOS line endings.

            If you wan't to work with UNIX file endings without a temporary conversion to DOS line endings and see therefore only 0A in the hex edit mode, you need to set UNIX/MAC file detection/conversion to Disable which does not really disable the detection, it just disables the temporary conversion to DOS and the prompt when a file is not a DOS file. Option Automatically convert to DOS format as I use just disables in real with Save file as input format (UNIX/MAC/DOS) also enabled only the prompt because the conversion from UNIX to DOS in the temporary file is also done when using Detect file type and prompt to change and decline permanent conversion to DOS.

            See also the topic Windows CRLF line break/ending/terminator versus Linux LF.

            Update: With UE v17.30.0.1011 and any later version a conversion from DOS to UNIX is done immediately instead of on next save.