How to convert between DOS and Unix file endings using Bluefish on Linux. …
Newlines, also known as line breaks or end-of-line (EOL) characters, are handled differently on different operating systems. In the Unix world (including Linux), a newline is indicated with a line feed (sometimes written as LF or n). In the DOS world (including Windows), a newline is indicated by a carriage return followed by a line feed (sometimes written as CR-LF or rn).
This can be a problem if you are writing code destined for a different operating system, or editing a file originally written on a different OS. I deal with this problem by configuring my preferred code editor, Bluefish, to easily make these conversions using dos2unix. Naturally, you'll need to have Bluefish and dos2unix installed.
In Edit – Preferences – External filters, press "Add". A new entry labeled "Untitled" will appear. Select and then click it to edit its name. Rename it to something like "Line breaks: DOS to Unix" and press enter to apply it. Now click to the right of the new name, in the "Command" column, to enter a command. Enter the following:
| dos2unix –dtu |
Press enter to apply it. Now repeat the process, creating the label "Line breaks: Unix to DOS" and the command | dos2unix –utd |. I then delete the default dos2unix command that comes out of the box. Close the Preferences window by pressing "OK".
To use, simply go to Tools – Filters and select your choice of DOS to Unix or Unix to DOS. Your file's line breaks will be converted. Notice that the file is now marked as changed, so save your work.
In my experience, many Linux code and text editors can gracefully handle DOS line endings, but many Windows code and text editors cannot. For that reason I usually use DOS line endings for files that have to be shared across platforms.
More ways to convert newlines