?? ch11_01.htm
字號:
<html><head><title>The awk Programming Language (UNIX in a Nutshell: System V Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Arnold Robbins" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="1-56592-427-4" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="UNIX in a Nutshell: System V Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Book Title" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch10_05.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch11_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h1 class="chapter">Chapter 11. The awk Programming Language</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4><p><a href="ch11_01.htm#sect1">Conceptual Overview</a><br /><a href="ch11_02.htm">Command-Line Syntax</a><br /><a href="ch11_03.htm">Patterns and Procedures</a><br /><a href="ch11_04.htm">Built-in Variables</a><br /><a href="ch11_05.htm">Operators</a><br /><a href="ch11_06.htm">Variables and Array Assignments</a><br /><a href="ch11_07.htm">User-Defined Functions</a><br /><a href="ch11_08.htm">Group Listing of awk Functions and Commands</a><br /><a href="ch11_09.htm">Implementation Limits</a><br /><a href="ch11_10.htm">Alphabetical Summary of Functions and Commands</a><br /></p></div><p><a name="unut-ch-11-ix-awk-programming-language" />This chapter presents the following topics:</p><ul><li><p>Conceptual overview</p></li><li><p>Command-line syntax</p></li><li><p>Patterns and procedures</p></li><li><p>Built-in variables</p></li><li><p>Operators</p></li><li><p>Variables and array assignment</p></li><li><p>User-defined functions</p></li><li><p>Group listing of functions and commands</p></li><li><p>Implementation limits</p></li><li><p>Alphabetical summary of functions and commands</p></li></ul><p>For more information, see <em class="citetitle">sed & awk</em>,listed in the <a href="biblio.htm">Bibliography</a>.</p><div class="sect1"><a name="unut-ch-11-sect-1" /><h2 class="sect1"><a name="sect1" />11.1. Conceptual Overview</h2><p><tt class="literal">awk</tt> is a pattern-matching program for processingfiles, especially when they are databases. The new version of<tt class="literal">awk</tt>, called <tt class="literal">nawk</tt>, providesadditional capabilities.<a href="#FOOTNOTE-10">[10]</a>Every modern Unix system comeswith a version of new <tt class="literal">awk</tt>, and its use is recommendedover old <tt class="literal">awk</tt>.</p><blockquote class="footnote"><a name="FOOTNOTE-10" /><p> [10]It really isn't so new.The additional features were added in 1984,and it was first shipped with System V Release 3.1 in 1987.Nevertheless, the name was never changed on most systems.</p></blockquote><p>Different systems vary in what the two versions are called.Some have <tt class="literal">oawk</tt> and <tt class="literal">awk</tt>, forthe old and new versions, respectively.Others have <tt class="literal">awk</tt> and <tt class="literal">nawk</tt>.Still others only have <tt class="literal">awk</tt>, which is the new version.This example shows what happens if your <tt class="literal">awk</tt>is the old one:</p><blockquote><pre class="code">$ <tt class="userinput"><b>awk 1 /dev/null</b></tt>awk: syntax error near line 1awk: bailing out near line 1</pre></blockquote><p><tt class="literal">awk</tt> exits silently if it is the new version.</p><p>Source code for the latest version of <tt class="literal">awk</tt>,from Bell Labs, can be downloadedstarting at Brian Kernighan's home page:<a href="http://cm.bell-labs.com/~bwk">http://cm.bell-labs.com/~bwk</a>.Michael Brennan's <tt class="literal">mawk</tt> is available viaanonymous FTP from<a href="ftp://ftp.whidbey.net/pub/brennan/mawk1.3.3.tar.gz">ftp://ftp.whidbey.net/pub/brennan/mawk1.3.3.tar.gz</a>.Finally,the Free Software Foundation has a version of <tt class="literal">awk</tt> called <tt class="literal">gawk</tt>, available from<a href="ftp://gnudist.gnu.org/gnu/gawk/gawk-3.0.4.tar.gz">ftp://gnudist.gnu.org/gnu/gawk/gawk-3.0.4.tar.gz</a>.All three programs implement “new” <tt class="literal">awk</tt>.Thus, references below such as “<tt class="literal">nawk</tt> only,”apply to all three.<tt class="literal">gawk</tt> has additional features.</p><p>With original <tt class="literal">awk</tt>, you can:</p><ul><li><p>Think of a text file as made up of records and fields in a textual database.</p></li><li><p>Perform arithmetic and string operations.</p></li><li><p>Use programming constructs such as loops and conditionals.</p></li><li><p>Produce formatted reports.</p></li></ul><p>With <tt class="literal">nawk</tt>, you can also:</p><ul><li><p>Define your own functions.</p></li><li><p>Execute Unix commands from a script.</p></li><li><p>Process the results of Unix commands.</p></li><li><p>Process command-line arguments more gracefully.</p></li><li><p>Work more easily with multiple input streams.</p></li><li><p>Flush open output files and pipes (latest Bell Labs <tt class="literal">awk</tt>).</p></li></ul><p>In addition,with GNU <tt class="literal">awk</tt> (<tt class="literal">gawk</tt>), you can:</p><ul><li><p>Use regular expressions to separate records, as well as fields.</p></li><li><p>Skip to the start of the next file, not just the next record.</p></li><li><p>Perform more powerful string substitutions.</p></li><li><p>Retrieve and format system time values.</p></li></ul></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch10_05.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch11_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">10.5. Alphabetical Summary of sed Commands</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">11.2. Command-Line Syntax</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2003</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,88,96" href="../index.htm"><area shape="rect" coords="90,0,165,96" href="../upt/index.htm"><area shape="rect" coords="168,1,253,107" href="../mac/index.htm"><area shape="rect" coords="255,0,335,97" href="../korn/index.htm"><area shape="rect" coords="337,0,415,109" href="../unixnut/index.htm"><area shape="rect" coords="417,0,512,122" href="../sedawk/index.htm"><area shape="rect" coords="514,0,605,105" href="../lunix/index.htm"><area shape="rect" coords="611,2,694,121" href="../vi/index.htm"> </map></body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -