1

I used

antiword >filename.txt

To convert a .doc word document to a txt file. Then I edited the file in nano (also tried vim) and when the document is viewed in libre office and gvim or even text edit the line breaks are in the wrong place. The bit that was originally a .doc kept the correct line breaks but the bit I added did not. It displays correctly in the terminal editors but not in the GUI

A link to an example:

B was written in libre office C was written in nano.

http://pastebin.com/jshWMiih

Why is that so? Is there a way to fix it?

  • 1
    It would help if you uploaded the text file to Pastebin, and then left a comment with a link to the text file so we can see what's going on. – karel Apr 20 '13 at 14:46
  • Sorry, pastebin.com/jshWMiih. Its not the worst one but its the only one that I have where I have not manually changed the formatting later. – JGreen Apr 20 '13 at 16:23
3

You have mistaken word wrap for line breaks.

Compare:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

to

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

The first text is not word-wrapped while second one is wrapped to become more readable. In the source code of this answer, you can see the same text though. In order to make the text appear with consistent line breaks, provide the line breaks yourself (i.e., hit Enter

vim automatically breaks lines if you have textwidth (shorthand: tw) set (in normal mode, type :set tw=80 followed by Enter to have at most 80 characters on one line.). On your existing text, you can type gg to go to the beginning of your document followed by gqG to wrap from the current position to the end.

I have taken an alternative approach, the text was saved to a file foo.txt and I executed the fold -s foo.txt > foo-new.txt to get the below text:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in 
culpa qui officia deserunt mollit anim id est laborum.

For more information about the tools I have used:

  • vim textwidth setting: vim +h\ tw
  • "Wrap each input line to fit in specified width": man fold

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.