note and stuff to know about awk

This commit is contained in:
tille 2006-03-15 09:15:10 +00:00
parent 51af973eb4
commit 238be47eee
1 changed files with 8 additions and 1 deletions

View File

@ -20,6 +20,9 @@
<para>The basic function of <command>awk</command> is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line.</para>
<para>Programs in <command>awk</command> are different from programs in most other languages, because <command>awk</command> programs are <quote>data-driven</quote>: you describe the data you want to work with and then what to do when you
find it. Most other languages are <quote>procedural.</quote> You have to describe, in great detail, every step the program is to take. When working with procedural languages, it is usually much harder to clearly describe the data your program will process. For this reason, <command>awk</command> programs are often refreshingly easy to read and write.</para>
<note><title>What does it really mean?</title>
<para>Back in the 1970s, three programmers got together to create this language. Their names were Aho, Kernighan and Weinberger. They took the first character of each of their names and put them together. So the name of the language might just as well have been <quote>wak</quote>.</para>
</note>
</sect2>
<sect2 id="sect_06_01_02"><title>Gawk commands</title>
<para>When you run <command>awk</command>, you specify an <command>awk</command> <emphasis>program</emphasis> that tells <command>awk</command> what to do. The program consists of a series of <emphasis>rules</emphasis>. (It may also
@ -339,7 +342,11 @@ END { print "&lt;/pre&gt;\n&lt;/body&gt;\n&lt;/html&gt;" }
<para>The <command>gawk</command> utility interprets a special-purpose programming language, handling simple data-reformatting jobs with just a few lines of code. It is the free version of the general UNIX <command>awk</command> command.</para>
<para>This tools reads lines of input data and can easily recognize columned output. The <command>print</command> program is the most common for filtering and formatting defined fields.</para>
<para>On-the-fly variable declaration is straightforward and allows for simple calculation of sums, statistics and other operations on the processed input stream. Variables and commands can be put in <command>awk</command> scripts for background processing.</para>
<para>Other things you should know about <command>awk</command>:</para>
<itemizedlist>
<listitem><para>The language remains well-known on UNIX and alikes, but for executing similar tasks, <application>Perl</application> is now more commonly used. However, <command>awk</command> has a much steeper learning curve. In other words, <application>Perl</application> is more difficult to learn.</para></listitem>
<listitem><para>Both <application>Perl</application> and <command>awk</command> share the reputation of being incomprehensible, even to the actual authors of the programs that use these languages. So document your code!</para></listitem>
</itemizedlist>
</sect1>
<sect1 id="sect_06_05"><title>Exercises</title>