Re-formatting badly formatted text

You’ll find lots of badly formatted text in (pdf) ebooks and such. I used this script to quickly reformat most of the text:


while(<>) {

# remove stray newlines
s/(\w|\,|\;|\:)\s*\n/$1 /gm;

# remove hypenation

# print the row


Invoke the script like this:

$ < unformatted.txt > formatted.txt

Then you can import it in Libreoffice and export again as a PDF or save the odt and create an epub or mobi with Calibre.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.