| Foreword | xiii |
| Preface | xv |
| I. | The awk Language and gawk | 1 |
| 1. | Getting Started with awk | 3 |
| How to Run awk Programs | 4 |
| Datafiles for the Examples | 10 |
| Some Simple Examples | 11 |
| An Example with Two Rules | 13 |
| A More Complex Example | 14 |
| awk Statements Versus Lines | 15 |
| Other Features of AWK | 17 |
| When to Use AWK | 17 |
| 2. | Regular Expressions | 19 |
| How to Use Regular Expressions | 19 |
| Escape Sequences | 21 |
| Regular Expression Operators | 23 |
| Using Character Lists | 26 |
| gawk-Specific Regexp Operators | 28 |
| Case Sensitivity in Matching | 29 |
| How Much Text Matches? | 31 |
| Using Dynamic Regexps | 31 |
| 3. | Reading Input Files | 33 |
| How Input Is Split into Records | 33 |
| Examining Fields | 36 |
| Non-constant Field Numbers | 38 |
| Changing the Contents of a Field | 39 |
| Specifying How Fields Are Separated | 41 |
| Reading Fixed-Width Data | 46 |
| Multiple-Line Records | 48 |
| Explicit Input with getline | 51 |
| 4. | Printing Output | 58 |
| The print Statement | 58 |
| Examples of print Statements | 59 |
| Output Separators | 60 |
| Controlling Numeric Output with print | 61 |
| Using printf Statements for Fancier Printing | 62 |
| Redirecting Output of print and printf | 68 |
| Special Filenames in gawk | 70 |
| Closing Input and Output Redirections | 74 |
| 5. | Expressions | 78 |
| Constant Expressions | 79 |
| Using Regular Expression Constants | 81 |
| Variables | 82 |
| Conversion of Strings and Numbers | 84 |
| Arithmetic Operators | 85 |
| String Concatenation | 87 |
| Assignment Expressions | 88 |
| Increment and Decrement Operators | 92 |
| True and False in awk | 93 |
| Variable Typing and Comparison Expressions | 94 |
| Boolean Expressions | 97 |
| Conditional Expressions | 99 |
| Function Calls | 99 |
| Operator Precedence (How Operators Nest) | 101 |
| 6. | Patterns, Actions, and Variables | 103 |
| Pattern Elements | 103 |
| Using Shell Variables in Programs | 109 |
| Actions | 110 |
| Control Statements in Actions | 111 |
| Built-in Variables | 120 |
| 7. | Arrays in AWK | 129 |
| Introduction to Arrays | 130 |
| Referring to an Array Element | 132 |
| Assigning Array Elements | 133 |
| Basic Array Example | 133 |
| Scanning All Elements of an Array | 134 |
| The delete Statement | 135 |
| Using Numbers to Subscript Arrays | 136 |
| Using Uninitialized Variables as Subscripts | 137 |
| Multidimensional Arrays | 138 |
| Scanning Multidimensional Arrays | 139 |
| Sorting Array Values and Indices with gawk | 140 |
| 8. | Functions | 142 |
| Built-in Functions | 142 |
| User-Defined Functions | 166 |
| 9. | Internationalization with GAWK | 174 |
| Internationalization and Localization | 174 |
| GNU gettext | 175 |
| Internationalizing awk Programs | 177 |
| Translating AWK Programs | 179 |
| A Simple Internationalization Example | 182 |
| GAWK Can Speak Your Language | 183 |
| 10. | Advanced Features of gawk | 185 |
| Allowing Nondecimal Input Data | 185 |
| Two-Way Communications with Another Process | 186 |
| Using gawk for Network Programming | 188 |
| Using gawk with BSD Portals | 189 |
| Profiling Your AWK Programs | 190 |
| 11. | Running awk and GAWK | 194 |
| Invoking AWK | 194 |
| Command-Line Options | 195 |
| Other Command-Line Arguments | 200 |
| The AWKPATH Environment Variable | 201 |
| Obsolete Options and/or Features | 202 |
| Known Bugs in GAWK | 203 |
| II. | Using awk and GAWK | 205 |
| 12. | A Library of awk Functions | 207 |
| Naming Library Function Global Variables | 208 |
| General Programming | 210 |
| Datafile Management | 218 |
| Processing Command-Line Options | 222 |
| Reading the User Database | 228 |
| Reading the Group Database | 232 |
| 13. | Practical awk Programs | 237 |
| Running the Example Programs | 237 |
| Reinventing Wheels for Fun and Profit | 238 |
| A Grab Bag of awk Programs | 259 |
| 14. | Internetworking with GAWK | 281 |
| Networking with GAWK | 281 |
| Some Applications and Techniques | 305 |
| Related Links | 323 |
| III. | Appendixes | 325 |
| A. | The Evolution of the AWK Language | 327 |
| B. | Installing GAWK | 337 |
| C. | Implementation Notes | 350 |
| D. | Basic Programming Concepts | 367 |
| E. | GNU General Public License | 374 |
| F. | GNU Free Documentation License | 382 |
| Glossary | 391 |
| Index | 403 |