📄 ch43_18.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 43] 43.18 How nroff Makes Bold and Underline; How to Remove It</TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:52:00Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch43_01.htm"TITLE="43. Printing"><LINKREL="prev"HREF="ch43_17.htm"TITLE="43.17 Don't Have nroff? Try gnroff or awf "><LINKREL="next"HREF="ch43_19.htm"TITLE="43.19 Removing Leading Tabs and Other Trivia "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_17.htm"TITLE="43.17 Don't Have nroff? Try gnroff or awf "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.17 Don't Have nroff? Try gnroff or awf "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 43<BR>Printing</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_19.htm"TITLE="43.19 Removing Leading Tabs and Other Trivia "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.19 Removing Leading Tabs and Other Trivia "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0088">43.18 How nroff Makes Bold and Underline; How to Remove It</A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48536"></A><ACLASS="indexterm"NAME="AUTOID-48538"></A><ACLASS="indexterm"NAME="AUTOID-48540"></A><ACLASS="indexterm"NAME="AUTOID-48543"></A>The UNIX formatter <EMCLASS="emphasis">nroff</EM> produces output for lineprinters and CRT displays. To achieve such special effectsas emboldening, it outputs the characterfollowed by a backspace and then outputs the same characteragain. A sample of it viewed with a text editor or<SPANCLASS="link"><EMCLASS="emphasis">cat -v</EM> (<ACLASS="linkend"HREF="ch25_07.htm"TITLE="Show Non-Printing Characters with cat -v or od -c ">25.7</A>)</SPAN>might look like:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">N^HN^HN^HNA^HA^HA^HAM^HM^HM^HME^HE^HE^HE</PRE></BLOCKQUOTE></P><PCLASS="para">which emboldens the word "NAME." There are three overstrikesfor each character output. Similarly, underlining is achieved byoutputting an underscore, a backspace, and then the character to beunderlined. Some pagers, such as<SPANCLASS="link"><EMCLASS="emphasis">less</EM> (<ACLASS="linkend"HREF="ch25_04.htm"TITLE='The "less" Pager: More than "more"'>25.4</A>)</SPAN>,take advantage of overstruck text. But there are many times when it'snecessary to strip these special effects; for example, if you want to<EMCLASS="emphasis">grep</EM> through formatted <EMCLASS="emphasis">man pages</EM> (as we do in article<ACLASS="xref"HREF="ch50_03.htm"TITLE="apropos on Systems Without apropos ">50.3</A>).There are a number of ways to get rid of these decorations. Theeasiest way to do it is to use a utility like <EMCLASS="emphasis">col</EM>, <EMCLASS="emphasis">colcrt</EM>,or <EMCLASS="emphasis">ul</EM>:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48563"></A><ACLASS="indexterm"NAME="AUTOID-48566"></A><ACLASS="indexterm"NAME="AUTOID-48569"></A>With <EMCLASS="emphasis">col</EM>, use the command:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>col -b <</B></CODE> <CODECLASS="replaceable"><I>nroffoutput </I></CODE><CODECLASS="userinput"><B>> </B></CODE><CODECLASS="replaceable"><I>strippedoutput</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">-b</EM> option tells <EMCLASS="emphasis">col</EM> to strip all backspaces (and thecharacter preceding the backspace) from the file. <EMCLASS="emphasis">col</EM> doesn'tread from files; you need to redirect input from a pipe-or, as above,with the shell<SPANCLASS="link"><CODECLASS="literal"><</CODE> (<ACLASS="linkend"HREF="ch13_01.htm#UPT-ART-1023"TITLE="Using Standard Input and Output">13.1</A>)</SPAN>file-redirection character.<EMCLASS="emphasis">col</EM> is available on System V and BSD UNIX.Under System V, add the <EMCLASS="emphasis">-x</EM> option to avoid changingspaces to TABs.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48588"></A>With <EMCLASS="emphasis">colcrt</EM>, use a command like:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>colcrt - </B></CODE><CODECLASS="replaceable"><I>nroffoutput </I></CODE><CODECLASS="userinput"><B>></B></CODE> <CODECLASS="replaceable"><I>strippedoutput</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The <EMCLASS="emphasis">-</EM> (dash) option (yes, that's an option) says "ignore underlining."If you omit it, <EMCLASS="emphasis">colcrt</EM> tries to save underlining by putting theunderscores on a separate line.For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">Refer to Installing System V for information about ---------- ------ -installing optional software.</PRE></BLOCKQUOTE></P><PCLASS="para"><EMCLASS="emphasis">colcrt</EM> is only available under BSD; in any case, <EMCLASS="emphasis">col</EM> isprobably preferable.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48607"></A><ACLASS="indexterm"NAME="AUTOID-48610"></A><ACLASS="indexterm"NAME="AUTOID-48612"></A><ACLASS="indexterm"NAME="AUTOID-48615"></A><ACLASS="indexterm"NAME="AUTOID-48618"></A><EMCLASS="emphasis">ul</EM> reads your<EMCLASS="emphasis">TERM</EM> environment variable, and tries to translate backspace (underlineand overstrike) into something your terminal can understand.It'sused like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ul </B></CODE><CODECLASS="replaceable"><I>nroffoutput</I></CODE></PRE></BLOCKQUOTE></P><PCLASS="para">The <CODECLASS="literal">-t </CODE><CODECLASS="replaceable"><I>term</I></CODE> option lets you specify a terminal type; itoverrides the<SPANCLASS="link"><EMCLASS="emphasis">TERM</EM> (<ACLASS="linkend"HREF="ch05_10.htm"TITLE="Finding What Terminal Names You Can Use ">5.10</A>)</SPAN>variable.I think that <EMCLASS="emphasis">ul</EM> is probably the least useful of these commands;it tries to be too intelligent, and doesn't always do what you want.</P></LI></UL><PCLASS="para">Both <EMCLASS="emphasis">col</EM> and <EMCLASS="emphasis">colcrt</EM> attempt to handle "half linefeeds"(used to print superscripts and subscripts) reasonably.Many printershandle half linefeeds correctly, but most terminals can't deal withthem.</P><PCLASS="para">Here's one other solution to the problem: a simple<SPANCLASS="link"><EMCLASS="emphasis">sed</EM> (<ACLASS="linkend"HREF="ch34_24.htm"TITLE="Quick Reference: sed ">34.24</A>)</SPAN>script.The virtue of this solution is that you can elaborate on it, addingother features that you'd like, or integrating it into larger<EMCLASS="emphasis">sed</EM> scripts.The following <EMCLASS="emphasis">sed</EM> command removes the sequences for emboldeningand underscoring: </P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">s/.^H//g</PRE></BLOCKQUOTE></P><PCLASS="para">It removes any character preceding the backspace along with thebackspace itself.In the case of underlining, "." matches the underscore; for emboldening,it matches the overstrike character.Because it is applied repeatedly, multiple occurrences of the overstrikecharacter are removed, leaving a single character for each sequence.Note that <CODECLASS="literal">^H</CODE> is the single character CTRL-h.If you're a<EMCLASS="emphasis">vi</EM> user, enter this character by typing<SPANCLASS="link">CTRL-v followed by CTRL-h (<ACLASS="linkend"HREF="ch31_06.htm"TITLE="Protecting Keys from Interpretation by ex ">31.6</A>)</SPAN>.If you're an <EMCLASS="emphasis">emacs</EM> user, type<SPANCLASS="link">CTRL-q followed by CTRL-h (<ACLASS="linkend"HREF="ch32_10.htm"TITLE="Inserting Binary Characters into Files ">32.10</A>)</SPAN>.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">DD</SPAN>, <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_17.htm"TITLE="43.17 Don't Have nroff? Try gnroff or awf "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.17 Don't Have nroff? Try gnroff or awf "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_19.htm"TITLE="43.19 Removing Leading Tabs and Other Trivia "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.19 Removing Leading Tabs and Other Trivia "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">43.17 Don't Have nroff? Try gnroff or awf </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">43.19 Removing Leading Tabs and Other Trivia </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -