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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
If you want to easily print a man doc I usually do it the graphical way:
man -Hfirefox command
Then you can print certain pages in your web browser. This isn't as powerful as doing it through the command line but it's a lot easier to get right since you can actually see what you're printing ahead of time. This may be important if you want to print a landscape document or something of that sort.
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.
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
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.)