Feeds:
Posts
Comments

Posts Tagged ‘text’

A Quick Intro to End-Of-Line

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.

If you’d like a more WYSIWYG approach, check out how to save and convert via Gedit.

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.

Converting Linux EOL to Windows via the Terminal

It’s easy enough to create new text files with Windows EOL in Ubuntu using the default Text Editor (Gedit), but what if you’ve created a whole bunch with the default Unix/Linux EOL and need to convert them for Windows users? Well, you can actually open them in Gedit and use Save As… to save over them (or to create copies), but for more than a couple of files this would be the long, complicated solution.

By far the quickest and easiest approach is to convert the offending files via the command-line. This way, you could batch-convert hundreds of such files at once, not have to do them individually.
There are actually quite a few ways to do this, but we’ll look at a couple of tiny packages you can install, and the related commands to use.

The first – the tofrodos package – is undoubtedly the most widely-used, so we’ll look at that in detail – especially since many of the guides out there are outdated, since the commands it contains have been renamed.

The second is a little package called flip, and since it’s tiny and won’t cause any issues, it’s worth installing as a backup (just in case. I found it useful after trying to get tofrodos going on a new system, before I found out the commands were changed).

There is no actual command tofrodos, as it is just the package that contains the commands todos and fromdos. Currently, the vast majority of online guides will list the commands as unix2dos and dos2unix, but as the developer states:

With this release the symlinks “unix2dos” and “dos2unix” are dropped from the package. This will allow the introduction of the original dos2unix package, which also supports conversion to MacOS style files.

So now you can choose to use either todos (to convert to Windows) and fromdos (to convert to Linux), or just fromdos with options (fromdos -u to convert to DOS, and fromdos -d to convert to UNIX, though obviously the -d option really isn’t needed, as it is the default behaviour for the fromdos command).

We’ll use todos, as it is easier to remember, and show how to alter a single file, or all text files in a given folder. When you’re ready to proceed, open a terminal in the folder containing the text file(s) and use one of the following commands (note that for the purpose of illustration, the .txt suffix is used, but you can specify any other extension for your text files).

To convert to DOS/Windows format:

Single file (remember to replace filename.txt with the actual name of the file)

todos filename.txt

All text files in a folder (if the extension differs to .txt, simply replace it in the command)

todos *.txt

Similarly, flip is easy to use:

flip -m filename.txt (or flip -m *.txt for multiple files).

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

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!

Buy Ubuntu Genius a Beer to say Thanks!

Advertisements

Read Full Post »

A new little extension for Ubuntu‘s file manager is nautilus-pastebin, which is a script written in Python that allows users to upload text-only files to an online pastebin service by simply right-clicking them. Each scrap of text has its own unique URL, which is placed in the clipboard ready for pasting into your web browser (or email if wanting to share the text with the recipient).

Once installed, all you have to do is right-click a text file, choose Pastebin from the context menu, and your text clip is uploaded. A notification should pop up under your system tray informing you where it has been saved to (as mentioned, the address will now be in memory ready for pasting).

To view it, simply paste the URL into your browser’s address bar.

If this seems like something you can do with, install the forementioned package via Synaptic, or enter the following into a terminal:

sudo apt-get install nautilus-pastebin

Users can also customise the extension’s behaviour by using nautilus-pastebin-configurator, an easy-to-use configuration tool that is also installed (just paste the command into a terminal or Alt+F2).

With it you can make the URL automatically open in your web browser, turn the notification on or off, force a confirmation message to appear before uploading the text, and change the pastebin service to another in the list.

ξξξξξξξξξξξξξξξξξξξξξξξξξξξξξξ

Click here for more Nautilus Extensions!

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

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!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »