Ping Services

Wednesday, October 26, 2011

How to join lines of broken text on Linux and Windows

Broken lines are a major formatting inconvenience. If you copy text from a PDF file, for example, you might have to manually join every single line; until now. I've written this tutorial to spare you of that inconvenience and will show you how to easily join multiple lines together on various text editors on Linux and Windows.


Here are a few lines of broken text that will be joined using various text editors:
Hello, I am a prime example
of ragged text. I will drive you
nuts as you are forced to go
to the end of each line and hit
delete to join it to the previous
line. One way I get to infuriate you
is when you copy text from a
PDF file to a text editor/processor.
MUAHAHAHAHA! Oh yes, I am evil.

Linux
I will provide instructions for two widely used editors on Linux, gedit and Kate.

Using gedit
Step 1:
Install the gedit-plugins package as well as gedit from your package manager.

Step 2:
Included among the gedit-plugins package is the Join/Split Lines plugin. Now that the package is installed, we can enable this plugin in gedit. Go to Edit » Preferences » Plugins and enable Join/Split Lines.


Step 3:
Paste the offending text into gedit, select the text and press CTRL+J.

THIS

BECOMES THIS


Using Kate
Kate is very full featured and does not require any extra plugins for the functionality to join lines.

Step 1: 
Install Kate from your package manager

Step 2:
Select the text and press CTRL+J



Windows
On Windows, we can use Microsoft Word intelligently in order to join lines.



Step 1:
First you will have to show all formatting marks. This can be done by clicking on the paragraph mark symbol on the formatting toolbar.


Now all formatting marks will be shown.

Step 2:
Now we can replace the paragraph marks with spaces using the Find and Replace dialog (F5). Typing ^p is the equivalent of the paragraph mark symbol. Under the replace text field, just press space once so that the words at the end of each line won't get joined with the words at the beginning of the next line.



Step 3:
Click on "Replace All"



Vim
Vim is a cross-platform and extremely powerful text editor with a 20 year history. I've only started using it and am still getting the hang of it. Under Vim, the command nJ, where n is the number of lines that you would like to join, lets you join lines. 


As there were 9 lines of text, I just typed 9J in command mode and voilĂ !


Hope you found this week's article useful.

NEXT WEEK: I've been using the newest Ubuntu for a few weeks now and have been writing a review as well. Stay tuned for a review of Ubuntu 11.10 next week.

Related articles
Convert a table in text form into table form

All articles The Review Meter How Software is reviewed

No comments:

Post a Comment