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

📄 0229-0232.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:




<HTML>

<HEAD>

<TITLE>Sams Teach Yourself Linux in 24 Hours:Preparing Documents:EarthWeb Inc.-</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311623 //-->

<!-- TITLE=Sams Teach Yourself Linux in 24 Hours//-->

<!-- AUTHOR=Bill Ball//-->

<!-- PUBLISHER=Macmillan Computer Publishing//-->

<!-- IMPRINT=Sams//-->

<!-- CHAPTER=15 //-->

<!-- PAGES=0229-0242 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->







<P><CENTER>

<a href="../ch14/0227-0228.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0233-0236.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-229"><P>Page 229</P></A>







<H3><A NAME="ch15_ 2">

Hour 15</A></H3>



<H2>

<A NAME="ch15_ 3">Preparing Documents

</A>

</H2>



<P>Hour 14, &quot;Text Processing,&quot; discussed text editing tools and programs

used to create, edit, and save documents. This hour introduces you to

programs and utilities used to format and print your text documents. It starts off

with a discussion of different text formatting programs, and shows you how

to easily format your documents for printing without using complicated

formatting commands. It then shows you how to use more complex programs

by using simple commands.

</P>



<P>The hour concludes with a discussion of the basics of document

printing under Linux, as well as detailed information about how to configure

your printer to get the best possible output.

</P>



<H3><A NAME="ch15_ 4">

Formatting Text

</A></H3>



<P>While you can do basic formatting of text documents using a text editor

or word processor, most of these programs for Linux lack the necessary

features to add page numbering, boldfacing, font changes, indenting, or other

fancy text layout.

</P>



<A NAME="PAGENUM-230"><P>Page 230</P></A>







<P>Producing nicely typeset documents by using the programs included with your

Linux distribution is usually a three-step process. First, you create the document with a

text editor. You intersperse your text with typesetting commands to create a certain effect

when you filter your document through a formatting program. The second step is to process

your document through the typesetting program to produce formatted output. The third

step is to either check your formatting by previewing the document, or if you're confident

about your formatting, to print the document.

</P>



<P>This section shows you how to use typesetting programs to produce nicely

typeset documents. It also discusses the basic syntax, or commands, that these programs recognize.

</P>



<H4><A NAME="ch15_ 5">

Formatting Text Using Text Filters

</A></H4>



<P>In Hour 14 you were introduced to some text filters to change the output of

different programs or the contents of a document. These filters can help you format your

documents if you don't want to learn a complex formatting program or use complicated

typesetting commands, and are useful for quickly building formatted documents with headers,

footers, margins, and page numbers.

</P>



<P>Sending directory listings or short text files directly to your printer without formatting

may be okay, but printing larger text files usually requires nicer formatting. One command

you can use is the pr command, found under the

/usr/bin directory. The pr command has 19 different command-line options to format documents. Look at the following example:

</P>



<!-- CODE SNIP //-->

<PRE>

# pr +4 -h &quot;Draft Number 1&quot; -o 8 &lt;mydocument.txt &gt;output.txt

</PRE>

<!-- END CODE SNIP //-->



<P>This command line formats the file

mydocument.txt, starting at page 4, with a header containing the date, time, page number, and the words &quot;Draft Number 1,&quot; with a

left margin of 8 spaces. Using the &gt; redirection operator, the formatted output is then

saved to a file called output.txt, which you can print at a later time.

</P>



<P>The pr program also formats selected streams of text. One handy use is to create

formatted columns. For example, if you have a paragraph, you can quickly create columns of text

by combining several filter programs and then formatting the text with the

-COLUMN command-line option.

</P>



<!-- CODE //-->

<PRE>

# cat cities.txt

Cinncinati, San Francisco, Philadelphia, Austin, Washington

D.C., Albany, Indianapolis, Raleigh, Chicago, Miami,

Norfolk, Savannah, Seattle, Pittsburgh, St. Louis, Phoenix,

Nashville, Las Vegas, Atlantic City

# cat cities.txt | sed `s/, /#/g' | tr &quot;#&quot; `\n' | sort | pr -l 1 -3

Albany                  Atlantic City           Chicago

Indianapolis            Las Vegas               Miami

Nashville               Norfolk                 Phoenix

Pittsburgh              Raleigh                 Savannah

Seattle                 St. Louis               Washington

</PRE>

<!-- END CODE //-->



<A NAME="PAGENUM-231"><P>Page 231</P></A>







<P>The preceding example is a list of cities, separated by commas. By using several

filters, including the pr command, the text has been formatted into a readable list,

sorted alphabetically. This command line works by first using the sed stream editor (discussed

in Hour 14) to change each comma and space to a pound (#) sign. The pound sign is

then translated to a carriage return, by the tr command (also discussed in Hour 14) and the

text, now a list of words, one per line, is fed into the

sort command. The sorted text is then fed into the

pr command to produce three columns of text (the

-l, or page length option, with a value of 1 has been used to inhibit the page header).

</P>



<P>You also can use the fmt command with the pr command, to change the word wrap, or

width of your text documents. The following example is part of a public-domain software

license (found under the /usr/doc/shadow-utils directory).

</P>



<!-- CODE //-->

<PRE>

# cat LICENSE

...

1.  You may make and give away verbatim copies of the source form of the

Standard Version of this Package without restriction, provided that you

duplicate all of the original copyright notices and associated

disclaimers.



2.  You may apply bug fixes, portability fixes and other modifications

derived from the Public Domain or from the Copyright Holder.  A Package

modified in such a way shall still be considered the Standard Version.

...

</PRE>

<!-- END CODE //-->



<P>While this text may be okay when printed on the screen, or by using the default

settings with the pr command, the text overruns lines if you use a left-hand margin of 10

spaces. Look at the following example,

</P>



<!-- CODE //-->

<PRE>

# pr -o 10 &lt; &lt;LICENSE

...



1.  You may make and give away verbatim copies of the source form of

the

          Standard Version of this Package without restriction, provided that

you



          duplicate all of the original copyright notices and associated

          disclaimers.



2.  You may apply bug fixes, portability fixes and other modifications

          derived from the Public Domain or from the Copyright Holder.  A Packag

e

          modified in such a way shall still be considered the Standard Version.

...

</PRE>

<!-- END CODE //-->



<P>The preceding certainly won't look nice when printed! To fix it, use the

fmt command to format the text into a smaller line width before formatting with the

pr command:

</P>



<!-- CODE //-->

<PRE>

# cat LICENSE | fmt -w 60 | pr -o 10

...



1.  You may make and give away verbatim copies of the

          source form of the Standard Version of this Package

</PRE>

<!-- END CODE //-->





<A NAME="PAGENUM-232"><P>Page 232</P></A>







<!-- CODE //-->

<PRE>



          without restriction, provided that you duplicate all of

          the original copyright notices and associated disclaimers.







2.   You may apply bug fixes, portability fixes and other

          modifications derived from the Public Domain or from the

          Copyright Holder.  A Package modified in such a way shall

          still be considered the Standard Version.



...

</PRE>

<!-- END CODE //-->



<P>As you can see, the text now fits nicely on your page when printed. But what if you

want to save paper and would like to see at least two pages of output on a single page? In

this case, use the mpage, or multiple page command to print several sheets of paper on a

single page. Look at the following example:

</P>



<!-- CODE SNIP //-->

<PRE>

# mpage -2 myfile.txt &gt;myfile.ps

</PRE>

<!-- END CODE SNIP //-->



<P>This command line uses the mpage command, found under the

/usr/bin directory, to create a PostScript file you can later print, which contains the contents of the

myfile.txt document as two side-by-side pages on each sheet of paper.

</P>



<TABLE BGCOLOR=#FFFF99><TR><TD>JUST A MINUTE</TD></TR><TR><TD>

<BLOCKQUOTE>

You can use the mpage command's -O, -E, or -R options to print full-duplex,

or back-to-back documents. This can be handy for producing small booklets

using letter-size paper with a printer that's not capable of printing on both sides

of each sheet. You also can set different margins, fonts, and order of printed

pages. See the mpage manual page for details.

</BLOCKQUOTE></TD></TR></TABLE>





<P>By using the fmt, pr, or mpage commands, along with other text filters, you can perform

quick and dirty rudimentary text formatting. If you want to try more complex formatting, use

a text formatting program.

</P>



<H4><A NAME="ch15_ 6">

Formatting Text with the groff Formatter

</A></H4>



<P>If you've used Linux for the past several hours and have read some of its manual pages,

you should be familiar with at least one complex formatting program:

groff. When you read a manual page with

</P>



<!-- CODE SNIP //-->

<PRE>

# man ls

</PRE>

<!-- END CODE SNIP //-->



<P>it is equivalent to the following:

</P>



<!-- CODE SNIP //-->

<PRE>

# nroff -man /usr/man/man1/ls.1 | less

</PRE>

<!-- END CODE SNIP //-->





<P>Notice that the nroff command is used on the command line

instead of groff. This is because the nroff command installed on your system is a shell script, written to use the GNU

groff formatting program to emulate the nroff command. All Linux manual pages are written

using a special set of nroff commands called man macros. You also can tell the

</P>



<P><CENTER>

<a href="../ch14/0227-0228.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0233-0236.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -