old-www/HOWTO/Man-Page/q10.html

264 lines
4.2 KiB
HTML

<HTML
><HEAD
><TITLE
>How do I get a plain text man
page without all that ^H^_ stuff?</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Linux Man Page Howto"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Polishing your man
page"
HREF="q9.html"><LINK
REL="NEXT"
TITLE="How do I get a high quality
PostScript man page?"
HREF="q11.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Linux Man Page Howto</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="q9.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="q11.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="Q10"
></A
>10. How do I get a plain text man
page without all that ^H^_ stuff?</H1
><P
>Have a look at <TT
CLASS="LITERAL"
>col</TT
>(1), because
<TT
CLASS="LITERAL"
>col</TT
> can filter out backspace sequences. Just in
case you can't wait that long:</P
><P
><TT
CLASS="LITERAL"
>funnyprompt$ groff -t -e -mandoc -Tascii manpage.1 |
col -bx &#62; manpage.txt</TT
></P
><P
>The <TT
CLASS="LITERAL"
>-t</TT
> and <TT
CLASS="LITERAL"
>-e</TT
> switches
tell <TT
CLASS="LITERAL"
>groff</TT
> to preprocess using
<TT
CLASS="LITERAL"
>tbl</TT
> and <TT
CLASS="LITERAL"
>eqn</TT
>. This is overkill
for man pages that don't require preprocessing but it does no
harm apart from a few CPU cycles wasted. On the other hand, not
using <TT
CLASS="LITERAL"
>-t</TT
> when it is actually required does harm:
the table is terribly formatted. You can even find out (well,
"guess" is a better word) what command is needed to
format a certain <TT
CLASS="LITERAL"
>groff</TT
> document (not just man
pages) by issuing</P
><P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>funnyprompt$ grog /usr/man/man7/signal.7
groff -t -man /usr/man/man7/signal.7</PRE
></FONT
></TD
></TR
></TABLE
>&#13;</P
><P
>"Grog" stands for "GROff Guess", and it
does what it says--guess. If it were perfect we wouldn't need
options any more. I've seen it guess incorrectly on macro
packages and on preprocessors. Here is a little perl script I wrote
that can delete the page headers and footers, thereby saving you a
few pages (and mother nature a tree) when printing long and
elaborate man pages. Save it in a file named
<TT
CLASS="LITERAL"
>strip-headers</TT
> &#38; chmod 755.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
> #!/usr/bin/perl -wn
# make it slurp the whole file at once:
undef $/;
# delete first header:
s/^\n*.*\n+//;
# delete last footer:
s/\n+.*\n+$/\n/g;
# delete page breaks:
s/\n\n+[^ \t].*\n\n+(\S+).*\1\n\n+/\n/g;
# collapse two or more blank lines into a single one:
s/\n{3,}/\n\n/g;
# see what's left...
print;</PRE
></FONT
></TD
></TR
></TABLE
><P
>You have to use it as the first filter after the
<TT
CLASS="LITERAL"
>man</TT
> command as it relies on the number of
newlines being output by <TT
CLASS="LITERAL"
>groff</TT
>. For
example:</P
><P
><TT
CLASS="LITERAL"
>funnyprompt$ man bash | strip-headers | col -bx &#62;
bash.txt</TT
></P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="q9.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="q11.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Polishing your man
page</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>How do I get a high quality
PostScript man page?</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>