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

📄 ch35_02.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 35] 35.2 Neatening Text with 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:57Z"><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_01.htm"TITLE="35.1 And Why Not? "><LINKREL="next"HREF="ch35_03.htm"TITLE="35.3 Alternatives to fmt "></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_01.htm"TITLE="35.1 And Why Not? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 35.1 And Why Not? "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_03.htm"TITLE="35.3 Alternatives to fmt "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 35.3 Alternatives to fmt "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-9907">35.2 Neatening Text with fmt </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-40106"></A><ACLASS="indexterm"NAME="AUTOID-40109"></A><ACLASS="indexterm"NAME="AUTOID-40111"></A>One of the problems with<SPANCLASS="link"><EMCLASS="emphasis">fold</EM> (<ACLASS="linkend"HREF="ch43_08.htm"TITLE="Fixing Margins with pr and fold ">43.8</A>)</SPAN>is that it breaks text at an arbitrary column position&nbsp;- even if thatposition happens to be in the middle of a word.It's a pretty primitive utility, designed to keep long lines fromprinting off the edge of a line printer page, and not much more.</P><PCLASS="para"><EMCLASS="emphasis">fmt</EM> can do a better job because it thinks in terms of languageconstructs like paragraphs.<EMCLASS="emphasis">fmt</EM> wraps lines continuously, rather than just folding the long ones.It assumes that paragraphs end at blank lines.</P><PCLASS="para">You can use <EMCLASS="emphasis">fmt</EM> for things like neatening lines of a mailmessage or a file that you're editing<SPANCLASS="link">with <EMCLASS="emphasis">vi</EM> (<ACLASS="linkend"HREF="ch30_37.htm"TITLE="Neatening Lines ">30.37</A>)</SPAN>.(Emacs has its own built-in line-neatener.)It's also great for shell programming and almost any place you have linesthat are too long or too short for your screen.&#13;</P><BLOCKQUOTECLASS="note"><PCLASS="para"><STRONG>NOTE:</STRONG> On at least one version of UNIX, <EMCLASS="emphasis">fmt</EM> is a disk initializer(disk formatter) command.Don't run <EMCLASS="emphasis">that</EM> command accidentally!Check your online manual page and see the <EMCLASS="emphasis">fmt</EM> equivalents below.</P></BLOCKQUOTE><PCLASS="para">There are a few different versions of <EMCLASS="emphasis">fmt</EM>, some fancier than others.In general, the program assumes that:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">Paragraphs have blank lines between them.</P></LI><LICLASS="listitem"><PCLASS="para">If a line is indented, keep the indentation.</P></LI><LICLASS="listitem"><PCLASS="para">The output lines should be about 70 characters wide.Some have a command line option to let you set this.For example,<CODECLASS="literal">fmt&nbsp;-132</CODE> (or, on some versions, <CODECLASS="literal">fmt&nbsp;-l&nbsp;132</CODE>) would reformatyour file to have lines with no more than 132characters on each.</P></LI><LICLASS="listitem"><PCLASS="para">It reads files or standard input.Lines will be written to standard output.</P></LI></UL><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="fmt">fmt</A><BR></TH><TDVALIGN="TOP">&#13;The GNU <EMCLASS="emphasis">fmt</EM> is on the CD-ROM.There are also a couple offreely available versions.Many versions of <EMCLASS="emphasis">fmt</EM> have options for other structured data.The<SPANCLASS="link"><EMCLASS="emphasis">-p</EM> option (<ACLASS="linkend"HREF="ch35_04.htm"TITLE="recomment: Clean Up Program Comment Blocks ">35.4</A>)</SPAN>reformats program source code.(If your <EMCLASS="emphasis">fmt</EM> doesn't have <EMCLASS="emphasis">-p</EM>, the<SPANCLASS="link"><EMCLASS="emphasis">recomment</EM> (<ACLASS="linkend"HREF="ch35_04.htm"TITLE="recomment: Clean Up Program Comment Blocks ">35.4</A>)</SPAN>script uses standard <EMCLASS="emphasis">fmt</EM> with <EMCLASS="emphasis">sed</EM> to do the same thing.)The <EMCLASS="emphasis">-s</EM> option breaks long lines at whitespace but doesn't joinshort lines to form longer ones.</TD></TR></TABLE><PCLASS="para">Alternatively, you can<SPANCLASS="link">make your own (<ACLASS="linkend"HREF="ch35_03.htm"TITLE="Alternatives to fmt ">35.3</A>)</SPAN>simple (and a little slower) version with<EMCLASS="emphasis">sed</EM> and <EMCLASS="emphasis">nroff</EM>.If you want to get fancy (and use some <EMCLASS="emphasis">nroff</EM> and/or <EMCLASS="emphasis">tbl</EM>coding), this will let you do automatically formatted texttables, bulleted lists, and much more.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN>, <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_01.htm"TITLE="35.1 And Why Not? "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 35.1 And Why Not? "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_03.htm"TITLE="35.3 Alternatives to fmt "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 35.3 Alternatives to fmt "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">35.1 And Why Not? </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.3 Alternatives to fmt </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 + -