Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The question is: how do you print only part of a man page?

Currently I do zcat manpage.1.gz | vim - and just remove everything I don't want to print. Then I pass that through groff and lpr. Are there better methods?

share|improve this question
add comment

2 Answers

I know that you can print a whole man page at once, in plain monospaced text, by doing something like

man mc | col -b | lpr -P printername

Or to print it "pretty" (Serif font, bold, italics etc.) by doing

zcat /usr/share/man/man1/mc.1.gz | groff -man -Tps | lpr -P printername

As this basically sends a postscript file to the printer, you can also save it to a PostScript file by doing

zcat /usr/share/man/man1/mc.1.gz | groff -man -Tps > mc.ps

But I have no idea if you can easily extract a certain page, pages, or sections.

share|improve this answer
1  
Some versions of the man command have a -t option as a shortcut for outputting postscript so you don't have to find the .1.gz file and type that long command, you can just man -t foo | lpr. On selecting sections, I doubt it can be done cleanly. –  Alan Curry Aug 12 '12 at 19:00
add comment

How about:

man ls | sed -n "5, 8p;8q" > print_this.txt # get lines 5 to 8

Then print with

lp -d <printer> print_this.txt

(Hint: The option (-o) switches of lp are very useful!)

But better yet: open in your editor, then mark the region. In Emacs:

M-x man RET ls

Then

M-x print-region

For this to work, the variable printer-name must be set. Or, use switches to lpr. (I see that you do not use Emacs, but this is of course possible in your editor as well.)

share|improve this answer
    
+1; Nice answer, clearly addressing the question. –  don_crissti May 5 '13 at 23:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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