Ultraedit – Line termination – Unix and Dos

UltraEdit automatically detects the type of line termination and shows it always for every file in the status bar at bottom of the main window (DOS, UNIX or MAC).

The type of line termination can be changed permanently for the current file by using the commands UNIX/MAC to DOS, DOS to MAC and DOS to UNIX in menu File – Conversions or alternatively on file save with command File – Save As by selecting a Line Terminator. But please note that the options selected in the Save As dialog are remembered and used whenever saving a file with using Save As dialog. So be careful when changing the options in the Save As dialog.

Because most servers for WWW are Unix/Linux servers and most clients are Windows computers, there are 2 different types for file transfers between a server and a client with FTP/SFTP. The binary mode transfers the files 1:1 without any modification. This mode must be used for binary files like images, but can be also used for text files like HTML or PHP files. The text mode can be used only for text files and is designed to handle the different types of line termination. On download from the server using the text mode before every line-feed a carriage return is inserted even if by mistake there is already a carriage-return before the line-feed. On upload to the server every 0D 0A byte sequence is replaced by 0A. So when you connect via FTP to your Linux server you could use for text files the text mode and for all other files the binary mode. However, when you edit the text files with UltraEdit, I suggest to use the binary mode for all files, see below why.

In UltraEdit you can configure the default handling of the different line terminations at Advanced – Configuration – File Handling – DOS/UNIX/MAC Handling. With the first option you can select which type of line termination should be used for new files. If you are mainly using UltraEdit to create text files for Windows, use the default setting DOS. But if you are using UltraEdit mainly for creating text files for a webpage hosted on a Linux server, set the option to UNIX. In case of once need a different line termination type as the one chosen in the configuration dialog, best use immediately after creating the new file with Ctrl+N the appropriate command in File – Conversions to change the type of line termination.

UNIX/MAC file detection/conversion in the configuration dialog is the most important line termination related setting. If you select Disable UltraEdit still auto-detects the different line termination types of the text files, but do not make any temporary conversions in the background. Detect file type and prompt to change causes a prompt if a file opened does not have DOS line terminations. If you confirm the question with Yes, the line terminators are permanently changed to DOS and with No the UNIX/MAC line terminators are only temporarily for the editing session converted to DOS, but the file is saved always with the original line termination type. The last option is the one I favor and strongly recommend: Automatically convert to DOS format. This is like second option, but without prompt and always pressing Yes.

Of course automatically converting a Linux file on load from UNIX to DOS permanently would not be a good idea when transfering the file later back to the Linux server. That’s why there is one further option: Save file as input format (UNIX/MAC/DOS) which should be enabled. The last option Only recognize DOS terminated lines (CR/LF) as new lines for editing is only required when something is wrong in a text file because it contains for example CR CR LF caused by uploading a DOS text file in binary mode to a Linux server, but downloading this file with text mode.

Summary:

Use always binary mode for all file transfers via FTP/SFTP.
Use for UNIX/MAC file detection/conversion the option Automatically convert to DOS format.
Enable the configuration setting Save file as input format (UNIX/MAC/DOS).
Set the default line termination type to DOS or UNIX depending on which type of new text files you normally create and use the appropriate conversion command if you once need a different line terminator for a new file.
When you open the files from Linux directly via a network share (Samba) or get it by email, these settings are also the best. These settings have also the big advantage that the type of line termination is always the same when using a Find/Replace in opened files independent if the saved file is a UNIX or a DOS file. Converting UNIX files always temporarily to DOS on file load is also better for working with macros or scripts on your files because then your macros/scripts work on both type of files when the macro/script was written to work on DOS files. And most important the data exchange via the Windows clipboard with other Windows applications works correct with these settings also for UNIX files. With setting Disable for UNIX/MAC file detection/conversion you can get very easily a text file where some lines have UNIX and some lines have DOS line terminations which is never good. By default the UltraEdit setting On paste convert line endings to destination type (UNIX/MAC/DOS) at Configuration – File Handling – Conversions is enabled to prevent mixing the line termination type in a file.

See also the topic DOS / Unix line terminator settings.

Source