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

📄 ch35_03.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 35] 35.3 Alternatives to fmt </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-08-04T21:47:58Z"><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="ch35_01.htm"TITLE="35. You Can't Quite Call This Editing"><LINKREL="prev"HREF="ch35_02.htm"TITLE="35.2 Neatening Text with fmt "><LINKREL="next"HREF="ch35_04.htm"TITLE="35.4 recomment: Clean Up Program Comment Blocks "></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="ch35_02.htm"TITLE="35.2 Neatening Text with fmt "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 35.2 Neatening Text with fmt "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 35<BR>You Can't Quite Call This Editing</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch35_04.htm"TITLE="35.4 recomment: Clean Up Program Comment Blocks "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 35.4 recomment: Clean Up Program Comment Blocks "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7801">35.3 Alternatives to fmt </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-40164"></A><ACLASS="indexterm"NAME="AUTOID-40166"></A><ACLASS="indexterm"NAME="AUTOID-40169"></A><SPANCLASS="link"><EMCLASS="emphasis">fmt</EM> (<ACLASS="linkend"HREF="ch35_02.htm"TITLE="Neatening Text with fmt ">35.2</A>)</SPAN>is hard to do without once you've learned about it.Unfortunately, it's not available in some versions of UNIX.You can get the GNU version from the CD-ROM.But it's also relatively easy to emulate with<SPANCLASS="link"><EMCLASS="emphasis">sed</EM> (<ACLASS="linkend"HREF="ch34_24.htm"TITLE="Quick Reference: sed ">34.24</A>)</SPAN>and<SPANCLASS="link"><EMCLASS="emphasis">nroff</EM> (<ACLASS="linkend"HREF="ch43_13.htm"TITLE="The Text Formatters nroff, troff, ditroff, ... ">43.13</A>)</SPAN>.Using those two utilities also lets you take advantage of themore-sophisticated formatting and flexibility that <EMCLASS="emphasis">sed</EM>and <EMCLASS="emphasis">nroff</EM><SPANCLASS="link">macros (<ACLASS="linkend"HREF="ch43_15.htm"TITLE="From a Source File to the Printer ">43.15</A>)</SPAN>can give you.(If you're doing anything really fancy, like<SPANCLASS="link">tables with <EMCLASS="emphasis">tbl</EM> (<ACLASS="linkend"HREF="ch43_15.htm"TITLE="From a Source File to the Printer ">43.15</A>)</SPAN>,[1]you might need<SPANCLASS="link"><EMCLASS="emphasis">col</EM> or <EMCLASS="emphasis">colcrt</EM> (<ACLASS="linkend"HREF="ch43_18.htm"TITLE="How nroff Makes Bold and Underline; How to Remove It">43.18</A>)</SPAN>to clean up <EMCLASS="emphasis">nroff</EM>'s output.)</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] [The combination of <EMCLASS="emphasis">tbl</EM>, <EMCLASS="emphasis">nroff</EM>, and <EMCLASS="emphasis">col</EM> can makeASCII tables in a few quick steps.The tables aren't sexy, but they can be sophisticated.They can be emailed or printed anywhere and don't requiresophisticated viewing equipment.I'm sad that so few people know <EMCLASS="emphasis">tbl</EM> these days.It's a powerful way to describe tables without worrying aboutbalancing columns or wrapping text in them.And, if you want nicer-looking output, you can feed the same<EMCLASS="emphasis">tbl</EM> file to<SPANCLASS="link"><EMCLASS="emphasis">groff</EM> (<ACLASS="linkend"HREF="ch43_16.htm"TITLE="groff ">43.16</A>)</SPAN>. &nbsp;- <EMCLASS="emphasis">JP</EM>&nbsp;]</P></BLOCKQUOTE><PCLASS="para">Here's the script:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">&#13;#!/bin/shsed '1i\.ll 72\.na\.hy 0\.pl 1' $* | nroff</PRE></BLOCKQUOTE></P><PCLASS="para">The reason this is so complicated is that,by default, <EMCLASS="emphasis">nroff</EM> makes some assumptions you need to change.For example, it assumes an 11-inch page (66 lines), and will addblank lines to a short file (or the end of a long file).The quick-and-dirty workaround to this is to manually put the <EMCLASS="emphasis">nroff</EM>request <EMCLASS="emphasis">.pl&nbsp;1</EM> (page length 1 line) at the top of the text you want toreformat. <EMCLASS="emphasis">nroff</EM> also tends to justify lines; you want to turnthis off with the <CODECLASS="literal">.na</CODE> request. You also want to turn offhyphenation (<CODECLASS="literal">.hy 0</CODE>), and you may want to set the line lengthto 72 instead of <EMCLASS="emphasis">nroff</EM>'s default 65, if only for consistency with thereal <EMCLASS="emphasis">fmt</EM> program. All these <EMCLASS="emphasis">nroff</EM> requestsget inserted before the first line of input by the <EMCLASS="emphasis">sed</EM><CODECLASS="literal">1i</CODE> command.</P><PCLASS="para">A fancier script would take a <EMCLASS="emphasis">-nn</EM> line-length option and turn itinto a <EMCLASS="emphasis">.ll</EM> request for <EMCLASS="emphasis">nroff</EM>, etc.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">TOR</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="ch35_02.htm"TITLE="35.2 Neatening Text with fmt "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 35.2 Neatening Text with fmt "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="ch35_04.htm"TITLE="35.4 recomment: Clean Up Program Comment Blocks "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 35.4 recomment: Clean Up Program Comment Blocks "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">35.2 Neatening Text with fmt </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">35.4 recomment: Clean Up Program Comment Blocks </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 + -