| [Top] | [Contents] | [Index] | [ ? ] |
This file documents awk, a program that you can use to select
particular records in a file and perform operations upon them.
This is Edition 3 of GAWK: Effective AWK Programming: A User's Guide for GNU Awk, for the 3.1.0 version of the GNU implementation of AWK.
Foreword Some nice words about this Web page. Preface What this Web page is about; brief history and acknowledgments. 2. Getting Started with awkA basic introduction to using awk. How to run anawk
program. Command-line syntax.
3. Regular Expressions All about matching things using regular expressions. 4. Reading Input Files How to read files and manipulate fields. 5. Printing Output How to print using awk. Describes theprintfstatements. Also describes redirection of output.6. Expressions Expressions are the basic building blocks of statements. 7. Patterns, Actions, and Variables Overviews of patterns and actions. 8. Arrays in awkThe description and use of arrays. Also includes array-oriented control statements. 9. Functions Built-in and user-defined functions. 10. Internationalization with gawkGetting gawkto speak your language.11. Advanced Features of gawkStuff for advanced users, specific to gawk.
12. Running awkandgawkHow to run gawk.13. A Library of awkFunctions14. Practical awkProgramsMany awkprograms with complete explanations.A. The Evolution of the awkLanguageThe evolution of the awklanguage.B. Installing gawkInstalling gawkunder various operating systems.C. Implementation Notes Notes about gawkextensions and possible future work.D. Basic Programming Concepts A very quick intoduction to programming concepts. Glossary An explanation of some unfamiliar terms. GNU General Public License Your right to copy and distribute gawk.
GNU Free Documentation License The license for this Web page. Index Concept and Variable Index.
History of awkandgawkThe history of gawkandawk.
1.0 A Rose by Any Other Name What name to use to find awk.1.1 Using This Book Using this Web page. Includes sample input files that you can use. 1.2 Typographical Conventions The GNU Project and This Book Brief history of the GNU project and this Web page. How to Contribute Helping to save the world. Acknowledgments 2.1 How to Run awkProgramsHow to run gawkprograms; includes command-line syntax.2.1.1 One-Shot Throw-Away awkProgramsRunning a short throw-away awkprogram.2.1.2 Running awkWithout Input FilesUsing no input files (input from terminal instead). 2.1.3 Running Long Programs Putting permanent awkprograms in files.2.1.4 Executable awkProgramsMaking self-contained awkprograms.2.1.5 Comments in awkProgramsAdding documentation to gawkprograms.2.1.6 Shell Quoting Issues More discussion of shell quoting issues. 2.2 Data Files for the Examples Sample data files for use in the awkprograms illustrated in this
Web page.
getline.
4.8.10 Summary of getlineVariants5.1 The The 5.2 Examples of Simple examples of 5.3 Output Separators The output separators and how to change them. 5.4 Controlling Numeric Output with Controlling Numeric Output With
5.5 Using printfStatements for Fancier PrintingThe printfstatement.5.5.1 Introduction to the printfStatementSyntax of the printfstatement.5.5.2 Format-Control Letters Format-control letters. 5.5.3 Modifiers for printfFormatsFormat-specification modifiers. 5.5.4 Examples Using printfSeveral examples. 5.6 Redirecting Output of printfHow to redirect output to multiple files and pipes. 5.7 Special File Names in gawkFile name interpretation in gawk.gawkallows access to inherited
file descriptors.
`&&' ("and") and `!' ("not").
5.7.1 Special Files for Standard Descriptors Special files for I/O. 5.7.2 Special Files for Process-Related Information Special files for process information. 5.7.3 Special Files for Network Communications Special files for network communications. 5.7.4 Special File Name Caveats Things to watch out for. 5.8 Closing Input and Output Redirections Closing Input and Output Files and Pipes. 6.1 Constant Expressions String, numeric and regexp constants. 6.1.1 Numeric and String Constants Numeric and string constants. 6.1.2 Octal and Hexadecimal Numbers What are octal and hex numbers. 6.1.3 Regular Expression Constants Regular Expression constants. 6.2 Using Regular Expression Constants When and how to use a regexp constant. 6.3 Variables Variables give names to values for later use. 6.3.1 Using Variables in a Program Using variables in your programs. 6.3.2 Assigning Variables on the Command Line Setting variables on the command-line and a summary of command-line syntax. This is an advanced method of input. 6.4 Conversion of Strings and Numbers The conversion of strings to numbers and vice versa. 6.5 Arithmetic Operators Arithmetic operations (`+', `-', etc.) 6.6 String Concatenation Concatenating strings. 6.7 Assignment Expressions Changing the value of a variable or a field. 6.8 Increment and Decrement Operators Incrementing the numeric value of a variable. 6.9 True and False in awkWhat is "true" and what is "false". 6.10 Variable Typing and Comparison Expressions How variables acquire types and how this affects comparison of numbers and strings with `<', etc. 6.11 Boolean Expressions Combining comparison expressions using boolean operators `||' ("or"),
6.12 Conditional Expressions Conditional expressions select between two subexpressions under control of a third subexpression. 6.13 Function Calls A function call is an expression. 6.14 Operator Precedence (How Operators Nest) How various operators nest. 7.1 Pattern Elements What goes into a pattern. 7.1.1 Regular Expressions as Patterns Using regexps as patterns. 7.1.2 Expressions as Patterns Any expression can be used as a pattern. 7.1.3 Specifying Record Ranges with Patterns Pairs of patterns specify record ranges. 7.1.4 The BEGINandENDSpecial PatternsSpecifying initialization and cleanup rules. 7.1.4.1 Startup and Cleanup Actions How and why to use BEGIN/END rules. 7.1.4.2 Input/Output from BEGINandENDRulesI/O issues in BEGIN/END rules. 7.1.5 The Empty Pattern The empty pattern, which matches every record. 7.2 Using Shell Variables in Programs How to use shell variables with awk.
7.3 Actions What goes into an action. 7.4 Control Statements in Actions Describes the various control statements in detail. 7.4.1 The if-elseStatementConditionally execute some awkstatements.7.4.2 The whileStatementLoop until some condition is satisfied. 7.4.3 The do-whileStatementDo specified action while looping until some condition is satisfied. 7.4.4 The forStatementAnother looping statement, that provides initialization and increment clauses. 7.4.5 The breakStatementImmediately exit the innermost enclosing loop. 7.4.6 The continueStatementSkip to the end of the innermost enclosing loop. 7.4.7 The nextStatementStop processing the current input record. 7.4.8 Using gawk'snextfileStatementStop processing the current file. 7.4.9 The exitStatementStop execution of awk.7.5 Built-in Variables Summarizes the built-in variables. 7.5.1 Built-in Variables That Control awkBuilt-in variables that you change to control awk.7.5.2 Built-in Variables That Convey Information Built-in variables where awkgives you information.7.5.3 Using ARGCandARGVWays to use ARGCandARGV.8.1 Introduction to Arrays 8.2 Referring to an Array Element How to examine one element of an array. 8.3 Assigning Array Elements How to change an element of an array. 8.4 Basic Array Example Basic Example of an Array 8.5 Scanning All Elements of an Array A variation of the forstatement. It loops through the indices of an array's existing elements.8.6 The deleteStatementThe deletestatement removes an element from an array.8.7 Using Numbers to Subscript Arrays How to use numbers as subscripts in awk.
8.8 Using Uninitialized Variables as Subscripts Using Uninitialized variables as subscripts. 8.9 Multidimensional Arrays Emulating multidimensional arrays in awk.
8.10 Scanning Multidimensional Arrays Scanning multidimensional arrays. 8.11 Sorting Array Values and Indices with gawkSorting array values and indices. 9.1 Built-in Functions Summarizes the built-in functions. 9.1.1 Calling Built-in Functions How to call built-in functions. 9.1.2 Numeric Functions Functions that work with numbers, including int,sinandrand.
9.1.3 String Manipulation Functions Functions for string manipulation, such as split,matchand
sprintf.
gawk.
C.2.2 Porting gawkto a New Operating SystemPorting gawkto a new operating system.C.3 Adding New Built-in Functions to gawkAdding new built-in functions to gawk.
C.3.1 A Minimal Introduction to gawkInternalsA brief look at some gawkinternals.C.3.2 Directory and File Operation Built-ins A example of new functions. C.3.2.1 Using chdirandstatWhat the new functions will do. C.3.2.2 C Code for chdirandstatThe code for internal file operations. C.3.2.3 Integrating the Extensions How to use an external extension. C.4 Probable Future Extensions New features that may be implemented one day. D.1 What a Program Does The high level view. D.2 Data Values in a Computer A very quick intro to data types. D.3 Floating-Point Number Caveats Stuff to know about floating-point numbers.