⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch43_19.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 43] 43.19 Removing Leading Tabs and Other Trivia </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:52:03Z"><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_18.htm"TITLE="43.18 How nroff Makes Bold and Underline; How to Remove It"><LINKREL="next"HREF="ch43_20.htm"TITLE="43.20 Displaying a troff Macro Definition "></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_18.htm"TITLE="43.18 How nroff Makes Bold and Underline; How to Remove It"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.18 How nroff Makes Bold and Underline; How to Remove It"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_20.htm"TITLE="43.20 Displaying a troff Macro Definition "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.20 Displaying a troff Macro Definition "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-2432">43.19 Removing Leading Tabs and Other Trivia </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48655"></A><ACLASS="indexterm"NAME="AUTOID-48658"></A><ACLASS="indexterm"NAME="AUTOID-48661"></A>In article <ACLASS="xref"HREF="ch43_18.htm"TITLE="How nroff Makes Bold and Underline; How to Remove It">43.18</A>we discussed several techniques for removing overstriking andunderlining from <EMCLASS="emphasis">nroff</EM> output.Of course, that's not the onlyproblem you'll face when you're working with <EMCLASS="emphasis">nroff</EM>.Here aresome more postprocessing tricks for <EMCLASS="emphasis">nroff</EM> files.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48669"></A>You may also want to remove strange escape sequences thatproduce formfeeds or various other printer functions.For example,you sometimes see the sequence<CODECLASS="literal">^[9</CODE> at the top of the formatted manual page.This escape sequence can be removed with the <EMCLASS="emphasis">sed</EM> command:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">s/^[9//g</PRE></BLOCKQUOTE></P><PCLASS="para">The ESC character is entered in <EMCLASS="emphasis">vi</EM> by typing <SPANCLASS="link">CTRL-v (<ACLASS="linkend"HREF="ch31_06.htm"TITLE="Protecting Keys from Interpretation by ex ">31.6</A>)</SPAN>followed by theESCkey.In Emacs, use<SPANCLASS="link">CTRL-q&nbsp;ESC (<ACLASS="linkend"HREF="ch32_10.htm"TITLE="Inserting Binary Characters into Files ">32.10</A>)</SPAN>.The number 9 is literal.</P><PCLASS="para">The typical manual page also uses leading spaces to establish theleft margin and to indent most of the text.On further inspection, you'll see that leading spaces precede headings (such as &quot;NAME&quot;), buta single tab precedes each line of text.Tabs may also appear unexpectedly in the text.Of course, using TABswherever possible is a good idea on the whole; on a mechanicalprinter, and even on modern CRT displays, it's much quicker to print aTAB than to move the cursor over several spaces.However, the TABs can cause trouble if your printer (or terminal) isn'tset correctly, or when you're trying to search for something in the text.</P><PCLASS="para">To eliminate the left margin and the unwanted TABs, use the followingtwo <EMCLASS="emphasis">sed</EM> commands:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">s/^[ <KBDCLASS="keycap">[TAB]</KBD>]*//s/<KBDCLASS="keycap">[TAB]</KBD>/ /g</PRE></BLOCKQUOTE></P><PCLASS="para">The first command looks for any number of TABs or spacesat the beginning of a line.The second command looks for a tab and replaces it with a singlespace.</P><PCLASS="para">Now, let's put all these pieces together&nbsp;- including the script tostrip underlines and overstrikes (from article<ACLASS="xref"HREF="ch43_18.htm"TITLE="How nroff Makes Bold and Underline; How to Remove It">43.18</A>).Here's a script called <EMCLASS="emphasis">sedman</EM> that incorporates all of thesetricks.</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">&#13;#!/bin/sed -f#sedman - deformat nroff-formatted man pages/.^H//gs/^[9//gs/^[ <KBDCLASS="keycap">[TAB]</KBD>]*//s/<KBDCLASS="keycap">[TAB]</KBD>/ /g</PRE></BLOCKQUOTE></P><PCLASS="para">Running this script on a typical manual pageproduces a file that looks like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">who                                                     whoNAMEwho - who is on the system?SYNOPSISwho [-a] [-b] [-d] [-H] [-l] [-p] [-q] [-r] [-s] [-t] [-T][-u] [file]who am iDESCRIPTIONwho can list the user's name, terminal line, login time,elapsed time since activity occurred on the line, and the...</PRE></BLOCKQUOTE></P><PCLASS="para">This doesn'teliminate the unnecessary blank linescaused by paging.See articles<ACLASS="xref"HREF="ch34_18.htm"TITLE="Multiline Delete ">34.18</A>,<ACLASS="xref"HREF="ch25_11.htm"TITLE="crush: A cat that Skips all Blank Lines ">25.11</A>,and<ACLASS="xref"HREF="ch25_10.htm"TITLE="Squash Extra Blank Lines ">25.10</A>for help with that.</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_18.htm"TITLE="43.18 How nroff Makes Bold and Underline; How to Remove It"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.18 How nroff Makes Bold and Underline; How to Remove It"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_20.htm"TITLE="43.20 Displaying a troff Macro Definition "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.20 Displaying a troff Macro Definition "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">43.18 How nroff Makes Bold and Underline; How to Remove It</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.20 Displaying a troff Macro Definition </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 &amp; 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 + -