# Formatting man pages (and similar)

This topic is 4260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

There are two things this affects (sample at bottom): 1) How to copy a man page into a text file. Those of you who have tried 'man ls > ls.txt' know this produces very messy output, with multiple characters all over the place for terminal output. 2) If you use 'script' to produce a typescript of a gdb session, it does the same thing (i.e. it produces multiple characters all over the place). Note that 'cat'ing or 'enscript'ing either file decent formatting, on screen or on the printer, respectively. My proffesor wants homework turned in using (2) (but he doesn't know how to fix the formatting), and I have succeeded with (1) in the past, but I can't remeber which tool I was using to process the output. 'nroff' and its relatives ('groff', 'troff') get rid of the multiple characters, but for some reason also eat all the newlines, so not very helpful. If anyone could piont me on the right direction, I would be very grateful...
LS(1)                            User Commands                           LS(1)

NNAAMMEE
ls - list directory contents

SSYYNNOOPPSSIISS
llss [_O_P_T_I_O_N]... [_F_I_L_E]...

DDEESSCCRRIIPPTTIIOONN
List  information  about  the FILEs (the current directory by default).
Sort entries alphabetically if none of --ccffttuuSSUUXX nor ----ssoorrtt.

Mandatory arguments to long options are  mandatory  for  short  options
too.

--aa, ----aallll
do not hide entries starting with .

--AA, ----aallmmoosstt--aallll
do not list implied . and ..



##### Share on other sites
Just find the original in /usr/share/man, gunzip it and use the resulting file. It's just normal text with some formatting commands in it. Optionally, you could use a tool to convert that manpage original to plain text (man2txt), HTML (man2html) or something else.

##### Share on other sites
I always just went in and edited my script files by hand, but the vast majority of people won't bother unless told to do so. If your professor hasn't told you how to clean it up, and can't come up with a better way to collect assignments, you probably don't have to bother. Just turn in the ugly file with all the special characters attached, and let the TA worry about it.

CM

##### Share on other sites
I just figured out the easiest way, and I am feeling really stupid about not thinking of this first.
Since I am using a terminal in a GUI environment (a Mac), I can either take the session itself, or 'cat' the script to the terminal, and then 'select all' and copy & paste. Viola, no weird formatting.

But I am still interested in doing this on the command line. It seems that *roff works perfectly, except that it eats duplicate newlines as well, compacting the output too much. But *roff is used internally by both my man formatter, and my enscript print command, so there must be a command-line switch or something to fix this behaviour.

If anyone has experience of *roff, please let me know, and thanks for your help.

##### Share on other sites
Woah, that brings me back a few decades. I can almost hear the squeal of the acoustic coupler dialling me in to the glory days. Flashbacks, man.

Try this.
 man -Tascii col | col -b >some.file

That gives me a pure ASCII-text file containing the man page for the col command. It was an important command to know when you were connected to the PDP on a hardcopy terminal.

##### Share on other sites
Quote:
 Original post by BregmaWoah, that brings me back a few decades. I can almost hear the squeal of the acoustic coupler dialling me in to the glory days. Flashbacks, man.Try this. man -Tascii col | col -b >some.fileThat gives me a pure ASCII-text file containing the man page for the col command. It was an important command to know when you were connected to the PDP on a hardcopy terminal.

Thank you mon, 'col -b' was the command I was trying to remember, it filters the output perfectly.

##### Share on other sites
I'm not actually in linux at the moment, so I can't check it, but doesn't "man man" work?

##### Share on other sites
Quote:
 Original post by smitty1276I'm not actually in linux at the moment, so I can't check it, but doesn't "man man" work?

Not sure what you mean there? 'man man' gives you a manual page for the 'man' program itself. What I was interested in is outputting a textual file of any man page to disk.
According to the man page for 'col', all that mess in the output is the backspace characters sent to the terminal, and col strips those out to give nice plain text files. It also works great on GDB sessions, so both my issues fixed.

• 23
• 10
• 19
• 15
• 14