| [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 1.0.6 of Effective AWK Programming,
for the 3.0.6 version of the GNU implementation
of AWK.
Preface What this Info file is about; brief history and acknowledgements. 1. Introduction What is the awklanguage; using this Info file.2. Getting Started with awkA basic introduction to using awk. How to run anawkprogram. Command line syntax.3. Useful One Line Programs Short, sample awkprograms.4. Regular Expressions All about matching things using regular expressions. 5. Reading Input Files How to read files and manipulate fields. 6. Printing Output How to print using awk. Describes theprintfstatements.
Also describes redirection of output.
7. Expressions Expressions are the basic building blocks of statements. 8. Patterns and Actions Overviews of patterns and actions. 9. Control Statements in Actions The various control statements are described in detail. 10. Built-in Variables 11. Arrays in awkThe description and use of arrays. Also includes array-oriented control statements. 12. Built-in Functions The built-in functions are summarized here. 13. User-defined Functions User-defined functions are described in detail. 14. Running awkHow to run gawk.15. A Library of awkFunctions16. Practical awkProgramsMany awkprograms with complete explanations.17. The Evolution of the awkLanguageThe evolution of the awklanguage.A. gawkSummarygawkOptions and Language Summary.B. Installing gawkInstalling gawkunder various operating systems.C. Implementation Notes Something about the implementation of gawk.
D. Glossary An explanation of some unfamiliar terms. GNU GENERAL PUBLIC LICENSE Your right to copy and distribute gawk.Index Concept and Variable Index.
History of awkandgawkThe history of gawkandawk.The GNU Project and This Book Brief history of the GNU project and this Info file. Acknowledgements 1.1 Using This Book Using this Info file. Includes sample input files that you can use. 1.2 Typographical Conventions 1.3 Data Files for the Examples Sample data files for use in the awkprograms illustrated in this Info file.2.1 A Rose By Any Other Name What name to use to find awk.2.2 How to Run awkProgramsHow to run gawkprograms; includes command line syntax.2.2.1 One-shot Throw-away awkProgramsRunning a short throw-away awkprogram.2.2.2 Running awkwithout Input FilesUsing no input files (input from terminal instead). 2.2.3 Running Long Programs Putting permanent awkprograms in files.2.2.4 Executable awkProgramsMaking self-contained awkprograms.2.2.5 Comments in awkProgramsAdding documentation to gawkprograms.2.3 A Very Simple Example A very simple example. 2.4 An Example with Two Rules A less simple one-line example with two rules. 2.5 A More Complex Example A more complex example. 2.6 awkStatements Versus LinesSubdividing or combining statements into lines. 2.7 Other Features of awk2.8 When to Use awkWhen to use gawkand when to use other things.4.1 How to Use Regular Expressions 4.2 Escape Sequences How to write non-printing characters. 4.3 Regular Expression Operators 4.4 Additional Regexp Operators Only in gawkOperators specific to GNU software. 4.5 Case-sensitivity in Matching How to do case-insensitive matching. 4.6 How Much Text Matches? How much text matches. 4.7 Using Dynamic Regexps 5.1 How Input is Split into Records Controlling how data is split into records. 5.2 Examining Fields An introduction to fields. 5.3 Non-constant Field Numbers 5.4 Changing the Contents of a Field 5.5 Specifying How Fields are Separated The field separator and how to change it. 5.5.1 The Basics of Field Separating How fields are split with single characters or simple strings. 5.5.2 Using Regular Expressions to Separate Fields Using regexps as the field separator. 5.5.3 Making Each Character a Separate Field Making each character a separate field. 5.5.4 Setting FSfrom the Command LineSetting FSfrom the command line.5.5.5 Field Splitting Summary Some final points and a summary table. 5.6 Reading Fixed-width Data Reading constant width data. 5.7 Multiple-Line Records Reading multi-line records. 5.8 Explicit Input with getlineReading files under explicit program control using the getlinefunction.5.8.1 Introduction to getlineIntroduction to the getlinefunction.5.8.2 Using getlinewith No ArgumentsUsing getlinewith no arguments.5.8.3 Using getlineInto a VariableUsing getlineinto a variable.5.8.4 Using getlinefrom a FileUsing getlinefrom a file.5.8.5 Using getlineInto a Variable from a FileUsing getlineinto a variable from a file.5.8.6 Using getlinefrom a PipeUsing getlinefrom a pipe.5.8.7 Using getlineInto a Variable from a PipeUsing getlineinto a variable from a pipe.5.8.8 Summary of getlineVariantsSummary Of getlineVariants.6.1 The The 6.2 Examples of Simple examples of 6.3 Output Separators The output separators and how to change them. 6.4 Controlling Numeric Output with Controlling Numeric Output With 6.5 Using printfStatements for Fancier PrintingThe printfstatement.6.5.1 Introduction to the printfStatementSyntax of the printfstatement.6.5.2 Format-Control Letters Format-control letters. 6.5.3 Modifiers for printfFormatsFormat-specification modifiers. 6.5.4 Examples Using printfSeveral examples. 6.6 Redirecting Output of printfHow to redirect output to multiple files and pipes. 6.7 Special File Names in gawkFile name interpretation in gawk.gawkallows access to inherited file
descriptors.
`<', etc.
6.8 Closing Input and Output Files and Pipes 7.1 Constant Expressions String, numeric, and regexp constants. 7.1.1 Numeric and String Constants Numeric and string constants. 7.1.2 Regular Expression Constants Regular Expression constants. 7.2 Using Regular Expression Constants When and how to use a regexp constant. 7.3 Variables Variables give names to values for later use. 7.3.1 Using Variables in a Program Using variables in your programs. 7.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. 7.4 Conversion of Strings and Numbers The conversion of strings to numbers and vice versa. 7.5 Arithmetic Operators Arithmetic operations (`+', `-', etc.) 7.6 String Concatenation Concatenating strings. 7.7 Assignment Expressions Changing the value of a variable or a field. 7.8 Increment and Decrement Operators Incrementing the numeric value of a variable. 7.9 True and False in awkWhat is "true" and what is "false". 7.10 Variable Typing and Comparison Expressions How variables acquire types, and how this affects comparison of numbers and strings with
("and") and `!' ("not").
7.11 Boolean Expressions Combining comparison expressions using boolean operators `||' ("or"), `&&'
7.12 Conditional Expressions Conditional expressions select between two subexpressions under control of a third subexpression. 7.13 Function Calls A function call is an expression. 7.14 Operator Precedence (How Operators Nest) How various operators nest. 8.1 Pattern Elements What goes into a pattern. 8.1.1 Kinds of Patterns A list of all kinds of patterns. 8.1.2 Regular Expressions as Patterns Using regexps as patterns. 8.1.3 Expressions as Patterns Any expression can be used as a pattern. 8.1.4 Specifying Record Ranges with Patterns Pairs of patterns specify record ranges. 8.1.5 The BEGINandENDSpecial PatternsSpecifying initialization and cleanup rules. 8.1.5.1 Startup and Cleanup Actions How and why to use BEGIN/END rules. 8.1.5.2 Input/Output from BEGINandENDRulesI/O issues in BEGIN/END rules. 8.1.6 The Empty Pattern The empty pattern, which matches every record. 8.2 Overview of Actions What goes into an action. 9.1 The if-elseStatementConditionally execute some awkstatements.9.2 The whileStatementLoop until some condition is satisfied. 9.3 The do-whileStatementDo specified action while looping until some condition is satisfied. 9.4 The forStatementAnother looping statement, that provides initialization and increment clauses. 9.5 The breakStatementImmediately exit the innermost enclosing loop. 9.6 The continueStatementSkip to the end of the innermost enclosing loop. 9.7 The nextStatementStop processing the current input record. 9.8 The nextfileStatementStop processing the current file. 9.9 The exitStatementStop execution of awk.10.1 Built-in Variables that Control awkBuilt-in variables that you change to control awk.
10.2 Built-in Variables that Convey Information Built-in variables where awkgives you information.10.3 Using ARGCandARGVWays to use ARGCandARGV.11.1 Introduction to Arrays 11.2 Referring to an Array Element How to examine one element of an array. 11.3 Assigning Array Elements How to change an element of an array. 11.4 Basic Array Example Basic Example of an Array 11.5 Scanning All Elements of an Array A variation of the forstatement. It loops through the indices of an array's existing elements.11.6 The deleteStatementThe deletestatement removes an element from an array.11.7 Using Numbers to Subscript Arrays How to use numbers as subscripts in awk.
11.8 Using Uninitialized Variables as Subscripts Using Uninitialized variables as subscripts. 11.9 Multi-dimensional Arrays Emulating multi-dimensional arrays in awk.
11.10 Scanning Multi-dimensional Arrays Scanning multi-dimensional arrays. 12.1 Calling Built-in Functions How to call built-in functions. 12.2 Numeric Built-in Functions Functions that work with numbers, including int,sinandrand.
12.3 Built-in Functions for String Manipulation Functions for string manipulation, such as split,match, and
sprintf.
12.4 Built-in Functions for Input/Output Functions for files and shell commands. 12.5 Functions for Dealing with Time Stamps Functions for dealing with time stamps. 13.1 Function Definition Syntax How to write definitions and what they mean. 13.2 Function Definition Examples An example function definition and what it does. 13.3 Calling User-defined Functions Things to watch out for. 13.4 The returnStatementSpecifying the value a function returns. 14.1 Command Line Options Command line options and their meanings. 14.2 Other Command Line Arguments Input file names and variable assignments. 14.3 The AWKPATHEnvironment VariableSearching directories for awkprograms.14.4 Obsolete Options and/or Features Obsolete Options and/or features. 14.5 Undocumented Options and Features 14.6 Known Bugs in gawk15.1 Simulating gawk-specific FeaturesWhat to do if you don't have gawk.15.2 Implementing nextfileas a FunctionTwo implementations of a nextfilefunction.15.3 Assertions A function for assertions in awkprograms.15.4 Rounding Numbers A function for rounding if sprintfdoes not do it correctly.15.5 Translating Between Characters and Numbers Functions for using characters as numbers and vice versa. 15.6 Merging an Array Into a String A function to join an array into a string. 15.7 Turning Dates Into Timestamps A function to turn a date into a timestamp. 15.8 Managing the Time of Day A function to get formatted times. 15.9 Noting Data File Boundaries A function for handling data file transitions. 15.10 Processing Command Line Options A function for processing command line arguments. 15.11 Reading the User Database Functions for getting user information. 15.12 Reading the Group Database Functions for getting group information. 15.13 Naming Library Function Global Variables How to best name private global variables in library functions. 16.1 Re-inventing Wheels for Fun and Profit Clones of common utilities. 16.1.1 Cutting Out Fields and Columns The cututility.16.1.2 Searching for Regular Expressions in Files The egreputility.16.1.3 Printing Out User Information The idutility.16.1.4 Splitting a Large File Into Pieces The splitutility.16.1.5 Duplicating Output Into Multiple Files The teeutility.16.1.6 Printing Non-duplicated Lines of Text The uniqutility.16.1.7 Counting Things The wcutility.16.2 A Grab Bag of awkProgramsSome interesting awkprograms.16.2.1 Finding Duplicated Words in a Document Finding duplicated words in a document. 16.2.2 An Alarm Clock Program An alarm clock. 16.2.3 Transliterating Characters A program similar to the trutility.16.2.4 Printing Mailing Labels Printing mailing labels. 16.2.5 Generating Word Usage Counts A program to produce a word usage count. 16.2.6 Removing Duplicates from Unsorted Text Eliminating duplicate entries from a history file. 16.2.7 Extracting Programs from Texinfo Source Files Pulling out programs from Texinfo source files. 16.2.8 A Simple Stream Editor 16.2.9 An Easy Way to Use Library Functions A wrapper for awkthat includes files.17.1 Major Changes between V7 and SVR3.1 The major changes between V7 and System V Release 3.1. 17.2 Changes between SVR3.1 and SVR4 Minor changes between System V Releases 3.1 and 4. 17.3 Changes between SVR4 and POSIX awkNew features from the POSIX standard. 17.4 Extensions in the Bell Laboratories awkNew features from the Bell Laboratories version of awk.17.5 Extensions in gawkNot in POSIXawkThe extensions in gawknot in POSIXawk.
A.1 Command Line Options Summary Recapitulation of the command line. A.2 Language Summary A terse review of the language. A.3 Variables and Fields Variables, fields, and arrays. A.3.1 Fields Input field splitting. A.3.2 Built-in Variables awk's built-in variables.A.3.3 Arrays Using arrays. A.3.4 Data Types Values in awkare numbers or strings.A.4 Patterns Patterns and Actions, and their component parts. A.4.1 Pattern Summary Quick overview of patterns. A.4.2 Regular Expressions Quick overview of regular expressions. A.5 Actions Quick overview of actions. A.5.1 Operators awkoperators.A.5.2 Control Statements The control statements. A.5.3 I/O Statements The I/O statements. A.5.4 printfSummaryA summary of printf.A.5.5 Special File Names Special file names interpreted internally. A.5.6 Built-in Functions Built-in numeric and string functions. A.5.7 Time Functions Built-in time functions. A.5.8 String Constants Escape sequences in strings. A.6 User-defined Functions Defining and calling functions. A.7 Historical Features Some undocumented but supported "features". B.1 The gawkDistributionWhat is in the gawkdistribution.B.1.1 Getting the gawkDistributionHow to get the distribution. B.1.2 Extracting the Distribution How to extract the distribution. B.1.3 Contents of the gawkDistributionWhat is in the distribution. B.2 Compiling and Installing gawkon UnixInstalling gawkunder various versions of Unix.B.2.1 Compiling gawkfor UnixCompiling gawkunder Unix.B.2.2 The Configuration Process How it's all supposed to work. B.3 How to Compile and Install gawkon VMSInstalling gawkon VMS.B.3.1 Compiling gawkon VMSHow to compile gawkunder VMS.B.3.2 Installing gawkon VMSHow to install gawkunder VMS.B.3.3 Running gawkon VMSHow to run gawkunder VMS.B.3.4 Building and Using gawkon VMS POSIXAlternate instructions for VMS POSIX. B.4 MS-DOS and OS/2 Installation and Compilation Installing and Compiling gawkon MS-DOS and OS/2B.5 Installing gawkon the Atari STB.5.1 Compiling gawkon the Atari STCompiling gawkon AtariB.5.2 Running gawkon the Atari STRunning gawkon AtariB.6 Installing gawkon an AmigaB.7 Reporting Problems and Bugs B.8 Other Freely Available awkImplementationsOther freely available awkimplementations.C.1 Downward Compatibility and Debugging How to disable certain gawkextensions.C.2 Making Additions to gawkMaking Additions To gawk.C.2.1 Adding New Features Adding code to the main body of gawk.C.2.2 Porting gawkto a New Operating SystemPorting gawkto a new operating system.C.3 Probable Future Extensions New features that may be implemented one day. C.4 Suggestions for Improvements Suggestions for improvements by volunteers.