Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Many text filess around Internet are word split before line reaches 80th character. I understand it is desirable by those using 80 character terminals. However I like sending longer articles to my kindle, but those files look very bad on it. See this picture:This is  LWN old issue that is automatically fetched and assembled into .mobi

80-charater splits are clearly visible when text ends in middle of line.

My question is: How to unwrap/uncut those lines? "By hand" method is, of course, out of discussion. EDIT: Lets clarify: I'm asking for script or other method that would be possible to run from Linux terminal. bash/ruby/python/perl/awk are ok.

Also, assume I have just plaintext, LWN is just example.

share|improve this question
part of the question is, how is the wrapping done in the first place, and how can you distinguish it from natural line breaks? the text you are receiving must have been modified on the source side, since it can't be re-flowed by your client. if you can answer that question, its a trivial matter to write a shell script to remove the wrapped line breaks. if you can't distinguish between the two, the job gets much harder though. – Frank Thomas Jun 22 '13 at 23:14
Most of the text I'd like to reflow have two \n`'s when natural break is (and it happens only when new paragraph is created, so there happends to be second newline created). So one null` would make no new line, two null's - two new lines – Szymon Szydełko Jun 22 '13 at 23:20
what editor are you using? Can it "Show CR LF"??? I think NotePad++ can.... most decent text editors can, and then you can do a find/replace on the chars. – Logman Jun 22 '13 at 23:27
@Logman you can also use the TextFX plugin (used to come with Notepad++, I think you have to DL it now from the Plugin Manager) to wrap/unwrap text of an arbitrary width (it will detect and handle the whitespace automagically). – Breakthrough Jun 22 '13 at 23:50
CR? At the end of line there are only LF's... Just like there I also use vim/sublimetext/kate (depending on mood) – Szymon Szydełko Jun 22 '13 at 23:54

I think that exactly what you want is performed by a simple:

fmt -w 80 < input > output
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .