Convert between DOS and Unix file endings within Bluefish

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.

CONFIGURATION
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".

USE
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.

REFERENCES
More ways to convert newlines

Advertisements

About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to Convert between DOS and Unix file endings within Bluefish

  1. Pingback: Developing Windows code on Linux | A maze of twisty little passages

  2. Pingback: Using Bluefish | A maze of twisty little passages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s