[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 awk
A 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 theprintf
statements. 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 awk
The description and use of arrays. Also includes array-oriented control statements. 9. Functions Built-in and user-defined functions. 10. Internationalization with gawk
Getting gawk
to speak your language.11. Advanced Features of gawk
Stuff for advanced users, specific to gawk
.
12. Running awk
andgawk
How to run gawk
.13. A Library of awk
Functions14. Practical awk
ProgramsMany awk
programs with complete explanations.A. The Evolution of the awk
LanguageThe evolution of the awk
language.B. Installing gawk
Installing gawk
under various operating systems.C. Implementation Notes Notes about gawk
extensions 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 awk
andgawk
The history of gawk
andawk
.
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 awk
ProgramsHow to run gawk
programs; includes command-line syntax.2.1.1 One-Shot Throw-Away awk
ProgramsRunning a short throw-away awk
program.2.1.2 Running awk
Without Input FilesUsing no input files (input from terminal instead). 2.1.3 Running Long Programs Putting permanent awk
programs in files.2.1.4 Executable awk
ProgramsMaking self-contained awk
programs.2.1.5 Comments in awk
ProgramsAdding documentation to gawk
programs.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 awk
programs illustrated in this
Web page.
getline
.
4.8.10 Summary of getline
Variants5.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 printf
Statements for Fancier PrintingThe printf
statement.5.5.1 Introduction to the printf
StatementSyntax of the printf
statement.5.5.2 Format-Control Letters Format-control letters. 5.5.3 Modifiers for printf
FormatsFormat-specification modifiers. 5.5.4 Examples Using printf
Several examples. 5.6 Redirecting Output of printf
How to redirect output to multiple files and pipes. 5.7 Special File Names in gawk
File name interpretation in gawk
.gawk
allows 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 awk
What 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 BEGIN
andEND
Special 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 BEGIN
andEND
RulesI/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
-else
StatementConditionally execute some awk
statements.7.4.2 The while
StatementLoop until some condition is satisfied. 7.4.3 The do
-while
StatementDo specified action while looping until some condition is satisfied. 7.4.4 The for
StatementAnother looping statement, that provides initialization and increment clauses. 7.4.5 The break
StatementImmediately exit the innermost enclosing loop. 7.4.6 The continue
StatementSkip to the end of the innermost enclosing loop. 7.4.7 The next
StatementStop processing the current input record. 7.4.8 Using gawk
'snextfile
StatementStop processing the current file. 7.4.9 The exit
StatementStop execution of awk
.7.5 Built-in Variables Summarizes the built-in variables. 7.5.1 Built-in Variables That Control awk
Built-in variables that you change to control awk
.7.5.2 Built-in Variables That Convey Information Built-in variables where awk
gives you information.7.5.3 Using ARGC
andARGV
Ways to use ARGC
andARGV
.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 for
statement. It loops through the indices of an array's existing elements.8.6 The delete
StatementThe delete
statement 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 gawk
Sorting 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
,sin
andrand
.
9.1.3 String Manipulation Functions Functions for string manipulation, such as split
,match
and
sprintf
.
gawk
.
C.2.2 Porting gawk
to a New Operating SystemPorting gawk
to a new operating system.C.3 Adding New Built-in Functions to gawk
Adding new built-in functions to gawk
.
C.3.1 A Minimal Introduction to gawk
InternalsA brief look at some gawk
internals.C.3.2 Directory and File Operation Built-ins A example of new functions. C.3.2.1 Using chdir
andstat
What the new functions will do. C.3.2.2 C Code for chdir
andstat
The 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.