Foreword to the Third Edition |
|
xv | |
Foreword to the Fourth Edition |
|
xvii | |
Preface |
|
xix | |
Part I. The awk Language |
|
|
1 Getting Started with awk |
|
|
3 | (18) |
|
|
3 | (8) |
|
One-Shot Throwaway awk Programs |
|
|
4 | (1) |
|
Running awk Without Input Files |
|
|
4 | (1) |
|
|
5 | (1) |
|
|
6 | (1) |
|
|
7 | (1) |
|
|
8 | (3) |
|
Datafiles for the Examples |
|
|
11 | (1) |
|
|
12 | (2) |
|
An Example with Two Rules |
|
|
14 | (1) |
|
|
15 | (1) |
|
awk Statements Versus Lines |
|
|
16 | (2) |
|
|
18 | (1) |
|
|
18 | (1) |
|
|
19 | (2) |
|
|
21 | (18) |
|
|
21 | (1) |
|
|
22 | (7) |
|
Other Command-Line Arguments |
|
|
29 | (1) |
|
|
30 | (1) |
|
The Environment Variables gawk Uses |
|
|
30 | (4) |
|
The AWKPATH Environment Variable |
|
|
31 | (1) |
|
The AWKLIBPATH Environment Variable |
|
|
32 | (1) |
|
Other Environment Variables |
|
|
32 | (2) |
|
|
34 | (1) |
|
Including Other Files into Your Program |
|
|
35 | (1) |
|
Loading Dynamic Extensions into Your Program |
|
|
36 | (1) |
|
Obsolete Options and/or Features |
|
|
37 | (1) |
|
Undocumented Options and Features |
|
|
37 | (1) |
|
|
37 | (2) |
|
|
39 | (16) |
|
How to Use Regular Expressions |
|
|
39 | (1) |
|
|
40 | (3) |
|
Regular Expression Operators |
|
|
43 | (3) |
|
Using Bracket Expressions |
|
|
46 | (2) |
|
|
48 | (1) |
|
|
49 | (1) |
|
gawk-Specific Regexp Operators |
|
|
50 | (2) |
|
Case Sensitivity in Matching |
|
|
52 | (2) |
|
|
54 | (1) |
|
|
55 | (34) |
|
How Input Is Split into Records |
|
|
55 | (5) |
|
Record Splitting with Standard awk |
|
|
55 | (3) |
|
Record Splitting with gawk |
|
|
58 | (2) |
|
|
60 | (1) |
|
Nonconstant Field Numbers |
|
|
61 | (1) |
|
Changing the Contents of a Field |
|
|
62 | (3) |
|
Specifying How Fields Are Separated |
|
|
65 | (6) |
|
Whitespace Normally Separates Fields |
|
|
66 | (1) |
|
Using Regular Expressions to Separate Fields |
|
|
66 | (1) |
|
Making Each Character a Separate Field |
|
|
67 | (1) |
|
Setting FS from the Command Line |
|
|
68 | (1) |
|
Making the Full Line Be a Single Field |
|
|
69 | (1) |
|
|
70 | (1) |
|
|
71 | (2) |
|
Defining Fields by Content |
|
|
73 | (2) |
|
|
75 | (2) |
|
Explicit Input with getline |
|
|
77 | (8) |
|
Using getline with No Arguments |
|
|
78 | (1) |
|
Using getline into a Variable |
|
|
79 | (1) |
|
Using getline from a File |
|
|
80 | (1) |
|
Using getline into a Variable from a File |
|
|
80 | (1) |
|
Using getline from a Pipe |
|
|
81 | (1) |
|
Using getline into a Variable from a Pipe |
|
|
82 | (1) |
|
Using getline from a Coprocess |
|
|
83 | (1) |
|
Using getline into a Variable from a Coprocess |
|
|
83 | (1) |
|
Points to Remember About getline |
|
|
83 | (2) |
|
Summary of getline Variants |
|
|
85 | (1) |
|
Reading Input with a Timeout |
|
|
85 | (2) |
|
Directories on the Command Line |
|
|
87 | (1) |
|
|
87 | (2) |
|
|
89 | (22) |
|
|
89 | (1) |
|
|
90 | (1) |
|
|
91 | (1) |
|
Controlling Numeric Output with print |
|
|
92 | (1) |
|
Using printf Statements for Fancier Printing |
|
|
93 | (7) |
|
Introduction to the printf Statement |
|
|
93 | (1) |
|
|
94 | (2) |
|
Modifiers for printf Formats |
|
|
96 | (3) |
|
|
99 | (1) |
|
Redirecting Output of print and printf |
|
|
100 | (3) |
|
Special Files for Standard Preopened Data Streams |
|
|
103 | (1) |
|
Special Filenames in gawk |
|
|
104 | (1) |
|
Accessing Other Open Files with gawk |
|
|
104 | (1) |
|
Special Files for Network Communications |
|
|
104 | (1) |
|
|
105 | (1) |
|
Closing Input and Output Redirections |
|
|
105 | (3) |
|
|
108 | (3) |
|
|
111 | (30) |
|
Constants, Variables, and Conversions |
|
|
111 | (8) |
|
|
111 | (3) |
|
Using Regular Expression Constants |
|
|
114 | (1) |
|
|
115 | (2) |
|
Conversion of Strings and Numbers |
|
|
117 | (2) |
|
Operators: Doing Something with Values |
|
|
119 | (8) |
|
|
119 | (2) |
|
|
121 | (1) |
|
|
122 | (3) |
|
Increment and Decrement Operators |
|
|
125 | (2) |
|
Truth Values and Conditions |
|
|
127 | (7) |
|
|
127 | (1) |
|
Variable Typing and Comparison Expressions |
|
|
128 | (4) |
|
|
132 | (2) |
|
|
134 | (1) |
|
|
134 | (2) |
|
Operator Precedence (How Operators Nest) |
|
|
136 | (2) |
|
Where You Are Makes a Difference |
|
|
138 | (1) |
|
|
139 | (2) |
|
7 Patterns, Actions, and Variables |
|
|
141 | (32) |
|
|
141 | (7) |
|
Regular Expressions as Patterns |
|
|
142 | (1) |
|
|
142 | (1) |
|
Specifying Record Ranges with Patterns |
|
|
143 | (2) |
|
The BEGIN and END Special Patterns |
|
|
145 | (2) |
|
The BEGINFILE and ENDFILE Special Patterns |
|
|
147 | (1) |
|
|
148 | (1) |
|
Using Shell Variables in Programs |
|
|
148 | (1) |
|
|
149 | (1) |
|
Control Statements in Actions |
|
|
150 | (10) |
|
|
150 | (1) |
|
|
151 | (1) |
|
|
151 | (1) |
|
|
152 | (2) |
|
|
154 | (1) |
|
|
155 | (1) |
|
|
156 | (1) |
|
|
157 | (1) |
|
|
158 | (1) |
|
|
159 | (1) |
|
|
160 | (12) |
|
Built-in Variables That Control awk |
|
|
160 | (3) |
|
Built-in Variables That Convey Information |
|
|
163 | (7) |
|
|
170 | (2) |
|
|
172 | (1) |
|
|
173 | (18) |
|
|
173 | (9) |
|
|
173 | (2) |
|
Referring to an Array Element |
|
|
175 | (1) |
|
|
176 | (1) |
|
|
177 | (1) |
|
Scanning All Elements of an Array |
|
|
178 | (1) |
|
Using Predefined Array Scanning Orders with gawk |
|
|
179 | (3) |
|
Using Numbers to Subscript Arrays |
|
|
182 | (1) |
|
Using Uninitialized Variables as Subscripts |
|
|
183 | (1) |
|
|
184 | (1) |
|
|
185 | (2) |
|
Scanning Multidimensional Arrays |
|
|
187 | (1) |
|
|
187 | (3) |
|
|
190 | (1) |
|
|
191 | (50) |
|
|
191 | (29) |
|
Calling Built-in Functions |
|
|
191 | (1) |
|
|
192 | (2) |
|
String-Manipulation Functions |
|
|
194 | (14) |
|
|
208 | (3) |
|
|
211 | (6) |
|
Bit-Manipulation Functions |
|
|
217 | (2) |
|
|
219 | (1) |
|
String-Translation Functions |
|
|
220 | (1) |
|
|
220 | (11) |
|
Function Definition Syntax |
|
|
221 | (2) |
|
Function Definition Examples |
|
|
223 | (1) |
|
Calling User-Defined Functions |
|
|
224 | (5) |
|
|
229 | (1) |
|
Functions and Their Effects on Variable Typing |
|
|
230 | (1) |
|
|
231 | (5) |
|
|
236 | (5) |
Part II. Problem Solving with awk |
|
|
10 A Library of awk Functions |
|
|
241 | (36) |
|
Naming Library Function Global Variables |
|
|
242 | (1) |
|
|
243 | (11) |
|
Converting Strings to Numbers |
|
|
244 | (1) |
|
|
245 | (2) |
|
|
247 | (1) |
|
The Cliff Random Number Generator |
|
|
247 | (1) |
|
Translating Between Characters and Numbers |
|
|
248 | (2) |
|
Merging an Array into a String |
|
|
250 | (1) |
|
|
250 | (2) |
|
Reading a Whole File at Once |
|
|
252 | (1) |
|
Quoting Strings to Pass to the Shell |
|
|
253 | (1) |
|
|
254 | (5) |
|
Noting Datafile Boundaries |
|
|
254 | (2) |
|
Rereading the Current File |
|
|
256 | (1) |
|
Checking for Readable Datafiles |
|
|
257 | (1) |
|
Checking for Zero-Length Files |
|
|
257 | (1) |
|
Treating Assignments as Filenames |
|
|
258 | (1) |
|
Processing Command-Line Options |
|
|
259 | (5) |
|
Reading the User Database |
|
|
264 | (5) |
|
Reading the Group Database |
|
|
269 | (4) |
|
Traversing Arrays of Arrays |
|
|
273 | (2) |
|
|
275 | (2) |
|
11 Practical awk Programs |
|
|
277 | (50) |
|
Running the Example Programs |
|
|
277 | (1) |
|
Reinventing Wheels for Fun and Profit |
|
|
278 | (21) |
|
Cutting Out Fields and Columns |
|
|
278 | (5) |
|
Searching for Regular Expressions in Files |
|
|
283 | (4) |
|
Printing Out User Information |
|
|
287 | (2) |
|
Splitting a Large File into Pieces |
|
|
289 | (1) |
|
Duplicating Output into Multiple Files |
|
|
290 | (2) |
|
Printing Nonduplicated Lines of Text |
|
|
292 | (4) |
|
|
296 | (3) |
|
A Grab Bag of awk Programs |
|
|
299 | (24) |
|
Finding Duplicated Words in a Document |
|
|
299 | (1) |
|
|
300 | (2) |
|
Transliterating Characters |
|
|
302 | (2) |
|
|
304 | (2) |
|
Generating Word-Usage Counts |
|
|
306 | (2) |
|
Removing Duplicates from Unsorted Text |
|
|
308 | (1) |
|
Extracting Programs from Texinfo Source Files |
|
|
309 | (3) |
|
|
312 | (2) |
|
An Easy Way to Use Library Functions |
|
|
314 | (7) |
|
Finding Anagrams from a Dictionary |
|
|
321 | (2) |
|
And Now for Something Completely Different |
|
|
323 | (1) |
|
|
323 | (4) |
Part III. Moving Beyond Standard awk with gawk |
|
|
12 Advanced Features of gawk |
|
|
327 | (18) |
|
Allowing Nondecimal Input Data |
|
|
327 | (1) |
|
Controlling Array Traversal and Array Sorting |
|
|
328 | (6) |
|
Controlling Array Traversal |
|
|
328 | (5) |
|
Sorting Array Values and Indices with gawk |
|
|
333 | (1) |
|
Two-Way Communications with Another Process |
|
|
334 | (3) |
|
Using gawk for Network Programming |
|
|
337 | (1) |
|
Profiling Your awk Programs |
|
|
338 | (4) |
|
|
342 | (3) |
|
13 Internationalization with gawk |
|
|
345 | (12) |
|
Internationalization and Localization |
|
|
345 | (1) |
|
|
346 | (2) |
|
Internationalizing awk Programs |
|
|
348 | (2) |
|
|
350 | (3) |
|
Extracting Marked Strings |
|
|
350 | (1) |
|
Rearranging printf Arguments |
|
|
351 | (1) |
|
|
352 | (1) |
|
A Simple Internationalization Example |
|
|
353 | (2) |
|
gawk Can Speak Your Language |
|
|
355 | (1) |
|
|
355 | (2) |
|
14 Debugging awk Programs |
|
|
357 | (20) |
|
Introduction to the gawk Debugger |
|
|
357 | (2) |
|
|
357 | (1) |
|
|
358 | (1) |
|
|
359 | (1) |
|
Sample gawk Debugging Session |
|
|
359 | (4) |
|
How to Start the Debugger |
|
|
359 | (1) |
|
|
360 | (3) |
|
|
363 | (11) |
|
|
364 | (1) |
|
|
365 | (2) |
|
Viewing and Changing Data |
|
|
367 | (2) |
|
|
369 | (1) |
|
Obtaining Information About the Program and the Debugger State |
|
|
369 | (3) |
|
|
372 | (2) |
|
|
374 | (1) |
|
|
374 | (1) |
|
|
375 | (2) |
|
15 Arithmetic and Arbitrary-Precision Arithmetic with gawk |
|
|
377 | (16) |
|
A General Description of Computer Arithmetic |
|
|
377 | (2) |
|
|
379 | (2) |
|
Arbitrary-Precision Arithmetic Features in gawk |
|
|
381 | (1) |
|
Floating-Point Arithmetic: Caveat Emptor! |
|
|
382 | (6) |
|
Floating-Point Arithmetic Is Not Exact |
|
|
382 | (2) |
|
Getting the Accuracy You Need |
|
|
384 | (1) |
|
Try a Few Extra Bits of Precision and Rounding |
|
|
385 | (1) |
|
|
385 | (2) |
|
Setting the Rounding Mode |
|
|
387 | (1) |
|
Arbitrary-Precision Integer Arithmetic with gawk |
|
|
388 | (1) |
|
Standards Versus Existing Practice |
|
|
389 | (2) |
|
|
391 | (2) |
|
16 Writing Extensions for gawk |
|
|
393 | (64) |
|
|
393 | (1) |
|
|
394 | (1) |
|
How It Works at a High Level |
|
|
394 | (2) |
|
|
396 | (35) |
|
|
397 | (2) |
|
General-Purpose Data Types |
|
|
399 | (3) |
|
Memory Allocation Functions and Convenience Macros |
|
|
402 | (1) |
|
|
403 | (1) |
|
|
404 | (9) |
|
|
413 | (1) |
|
|
413 | (1) |
|
|
413 | (1) |
|
Accessing and Updating Parameters |
|
|
414 | (1) |
|
|
414 | (5) |
|
|
419 | (9) |
|
|
428 | (1) |
|
|
429 | (2) |
|
How gawk Finds Extensions |
|
|
431 | (1) |
|
Example: Some File Functions |
|
|
431 | (11) |
|
|
431 | (3) |
|
C Code for chdir() and stat() |
|
|
434 | (6) |
|
Integrating the Extensions |
|
|
440 | (2) |
|
The Sample Extensions in the gawk Distribution |
|
|
442 | (10) |
|
|
442 | (3) |
|
|
445 | (1) |
|
Interface to fork(), wait(), and waitpid() |
|
|
446 | (1) |
|
Enabling In-Place File Editing |
|
|
447 | (1) |
|
Character and Numeric values: ord() and chr() |
|
|
448 | (1) |
|
|
448 | (1) |
|
|
449 | (1) |
|
|
449 | (1) |
|
Dumping and Restoring an Array |
|
|
450 | (1) |
|
|
450 | (1) |
|
|
451 | (1) |
|
|
452 | (1) |
|
|
452 | (1) |
|
|
453 | |
Part IV. Appendices |
|
|
A The Evolution of the awk Language |
|
|
457 | (12) |
|
|
469 | (22) |
|
C GNU General Public License |
|
|
491 | (14) |
Index |
|
505 | |