I like to copy man pages to my own offline documentation where I can highlight and supplement the information with my own notes. However, I always have a problem with the exported text containing linefeeds at the end of every line, including in the middle of paragraphs. The process of stripping away the unnecessary linefeeds is annoying and time consuming, and I was hoping to find a simple way to initially export the information with the linefeeds only in their proper places.

I have examined the man command man pages and surprising have not found a solution to this problem. The closest I have come to fixing the problem is to use the ‘-c’ option while stretching the terminal window to be as wide as possible, however this is not a very effective fix for large man pages with lengthy paragraphs.

One interesting thing the ‘-c’ option shows me is that the locations of the LFs are indeed possible to be modified by the man program— So why isn’t the program capable of just removing the unnecessary ones altogether? Is there a simple command I that I’ve missed somehow?

Thanks in advance..


From what you describe I guess you have text files with line breaks after a fixed width, which will look ugly in a window that is to small for this width. Right? If so you could use

    cat mytextfile | tr "\n" " " > mynewtextfile

to strip away all the newlines. There's not really a way for a program to decide which ones are "necessary" and which aren't.

If you want to keep all double newlines that might mark real paragraphs try something like that:

    cat myfile | tr "\n" "#" | sed s/"#\([^#]\)"/"\1"/g | tr "#" "\n" > mynewfile

...assuming that you do not have any meaningful # in the text (might use another dummy character instead if this is the case).

Another possibility might be to save HTML versions from e.g. http://linuxmanpages.com and edit those in an appropriate program.

  • 1
    man itself has an option to provide HTML output, if you install the groff package: man --html=cat ls – muru Oct 12 '14 at 15:38

Ah, I found the solution! You need to set the MANWIDTH environment variable before calling the man command, such as like this:

MANWIDTH=10000 man ls

This will set the width of the columns to be so wide that the linefeeds are never added in the middle of the paragraphs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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