A Quick Intro to End-Of-Line Conventions
Most people don’t realise that when they hit the Enter key to create a new paragraph in a text file, something very different is going on behind the scenes in the three major operating systems: Windows, Macintosh and Linux. The “end-of-line delimiter” (often expressed as “End-Of-Line“, “End of Line“, or just “EOL“) – which some of you know as the “line break” or “newline” – is a special character used to designate the end of a line within a text file.
UNIX-based operating systems (like all Linux distros and BSD derivatives) use the line feed character (\n or <LF>), “classic” Mac OS uses a carriage return (\r or <CR>), while DOS/Windows uses a carriage return followed by a line feed (\r\n or <CR><LF>). Now that Mac OS X is based on FreeBSD‘s file system, it follows the UNIX convention.
Now, the reason most people don’t know about all this is because nobody really should have to. But while users of Linux distros and Mac OS can open Windows text files in basically any available editor and not even know the difference, the same can’t be said for Windows users opening files created in one of the other operating systems.
If you type up a simple text file in Ubuntu and save it in the default “Unix/Linux” format, in Windows it will appear as one continuous paragraph, with black squares where the line breaks (or new paragraphs) should be. While you can open the file in a more advanced text editor (or proper word processor) to view it as it should look, others you’ve sent it to are just likely to double-click it and let it open in Notepad (which can only handle MS-DOS EOL).
But you can save text files as Windows EOL easily with Gedit, as well as convert to that from UNIX via the terminal, so hopefully the following guide will be of use.
For more detailed info on End-Of-Line, go to the Wikipedia page.
And if you find the editor you’re using to display Windows files in Ubuntu shows ^M instead of a line break (not very likely with even the most lightweight text editors, but something you’ll probably come across if you display the text in a terminal), check out how to convert to Unix/Linux.
Saving Windows Text Files in Text Editor (Gedit)
It’s actually very easy to create text files with Windows EOL in Ubuntu using the default Text Editor, Gedit. When saving a file, go to Line Ending in the dialogue box and choose Windows instead of the default Unix/Linux. For files that were previously created, you can open them in Gedit and use Save As… to convert them (or save copies with the correct EOL).
As you can see, that’s pretty easy, but for more than one or two files, it is way too much work, so check out how to batch-convert multiple files via the terminal.
Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n'chips for my time and effort! Many thanks!