Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ AWK Language Programming - Table of Contents

Media Vault

Software Library

Restoration Projects

Artifacts Sought

AWK Language Programming - Table of Contents

AWK Language Programming

A User's Guide for GNU AWK

Edition 1.0

January 1996

Arnold D. Robbins
Based on The GAWK Manual,
by Robbins, Close, Rubin, and Stallman


  • Preface
    • History of awk and gawk
    • The GNU Project and This Book
    • Acknowledgements
  • 1. Introduction
    • 1.1 Using This Book
      • Dark Corners
    • 1.2 Typographical Conventions
    • 1.3 Data Files for the Examples
  • 2. Getting Started with awk
    • 2.1 A Rose By Any Other Name
    • 2.2 How to Run awk Programs
      • 2.2.1 One-shot Throw-away awk Programs
      • 2.2.2 Running awk without Input Files
      • 2.2.3 Running Long Programs
      • 2.2.4 Executable awk Programs
      • 2.2.5 Comments in awk Programs
    • 2.3 A Very Simple Example
    • 2.4 An Example with Two Rules
    • 2.5 A More Complex Example
    • 2.6 awk Statements Versus Lines
    • 2.7 Other Features of awk
    • 2.8 When to Use awk
  • 3. Useful One Line Programs
  • 4. Regular Expressions
    • 4.1 How to Use Regular Expressions
    • 4.2 Escape Sequences
    • 4.3 Regular Expression Operators
    • 4.4 Additional Regexp Operators Only in gawk
    • 4.5 Case-sensitivity in Matching
    • 4.6 How Much Text Matches?
    • 4.7 Using Dynamic Regexps
  • 5. Reading Input Files
    • 5.1 How Input is Split into Records
    • 5.2 Examining Fields
    • 5.3 Non-constant Field Numbers
    • 5.4 Changing the Contents of a Field
    • 5.5 Specifying How Fields are Separated
      • 5.5.1 The Basics of Field Separating
      • 5.5.2 Using Regular Expressions to Separate Fields
      • 5.5.3 Making Each Character a Separate Field
      • 5.5.4 Setting FS from the Command Line
      • 5.5.5 Field Splitting Summary
    • 5.6 Reading Fixed-width Data
    • 5.7 Multiple-Line Records
    • 5.8 Explicit Input with getline
      • 5.8.1 Introduction to getline
      • 5.8.2 Using getline with No Arguments
      • 5.8.3 Using getline Into a Variable
      • 5.8.4 Using getline from a File
      • 5.8.5 Using getline Into a Variable from a File
      • 5.8.6 Using getline from a Pipe
      • 5.8.7 Using getline Into a Variable from a Pipe
      • 5.8.8 Summary of getline Variants
  • 6. Printing Output
    • 6.1 The print Statement
    • 6.2 Examples of print Statements
    • 6.3 Output Separators
    • 6.4 Controlling Numeric Output with print
    • 6.5 Using printf Statements for Fancier Printing
      • 6.5.1 Introduction to the printf Statement
      • 6.5.2 Format-Control Letters
      • 6.5.3 Modifiers for printf Formats
      • 6.5.4 Examples Using printf
    • 6.6 Redirecting Output of print and printf
    • 6.7 Special File Names in gawk
    • 6.8 Closing Input and Output Files and Pipes
  • 7. Expressions
    • 7.1 Constant Expressions
      • 7.1.1 Numeric and String Constants
      • 7.1.2 Regular Expression Constants
    • 7.2 Using Regular Expression Constants
    • 7.3 Variables
      • 7.3.1 Using Variables in a Program
      • 7.3.2 Assigning Variables on the Command Line
    • 7.4 Conversion of Strings and Numbers
    • 7.5 Arithmetic Operators
    • 7.6 String Concatenation
    • 7.7 Assignment Expressions
    • 7.8 Increment and Decrement Operators
    • 7.9 True and False in awk
    • 7.10 Variable Typing and Comparison Expressions
    • 7.11 Boolean Expressions
    • 7.12 Conditional Expressions
    • 7.13 Function Calls
    • 7.14 Operator Precedence (How Operators Nest)
  • 8. Patterns and Actions
    • 8.1 Pattern Elements
      • 8.1.1 Kinds of Patterns
      • 8.1.2 Regular Expressions as Patterns
      • 8.1.3 Expressions as Patterns
      • 8.1.4 Specifying Record Ranges with Patterns
      • 8.1.5 The BEGIN and END Special Patterns
        • 8.1.5.1 Startup and Cleanup Actions
        • 8.1.5.2 Input/Output from BEGIN and END Rules
      • 8.1.6 The Empty Pattern
    • 8.2 Overview of Actions
  • 9. Control Statements in Actions
    • 9.1 The if-else Statement
    • 9.2 The while Statement
    • 9.3 The do-while Statement
    • 9.4 The for Statement
    • 9.5 The break Statement
    • 9.6 The continue Statement
    • 9.7 The next Statement
    • 9.8 The nextfile Statement
    • 9.9 The exit Statement
  • 10. Built-in Variables
    • 10.1 Built-in Variables that Control awk
    • 10.2 Built-in Variables that Convey Information
    • 10.3 Using ARGC and ARGV
  • 11. Arrays in awk
    • 11.1 Introduction to Arrays
    • 11.2 Referring to an Array Element
    • 11.3 Assigning Array Elements
    • 11.4 Basic Array Example
    • 11.5 Scanning All Elements of an Array
    • 11.6 The delete Statement
    • 11.7 Using Numbers to Subscript Arrays
    • 11.8 Using Uninitialized Variables as Subscripts
    • 11.9 Multi-dimensional Arrays
    • 11.10 Scanning Multi-dimensional Arrays
  • 12. Built-in Functions
    • 12.1 Calling Built-in Functions
    • 12.2 Numeric Built-in Functions
    • 12.3 Built-in Functions for String Manipulation
    • 12.4 Built-in Functions for Input/Output
    • 12.5 Functions for Dealing with Time Stamps
  • 13. User-defined Functions
    • 13.1 Function Definition Syntax
    • 13.2 Function Definition Examples
    • 13.3 Calling User-defined Functions
    • 13.4 The return Statement
  • 14. Running awk
    • 14.1 Command Line Options
    • 14.2 Other Command Line Arguments
    • 14.3 The AWKPATH Environment Variable
    • 14.4 Obsolete Options and/or Features
    • 14.5 Undocumented Options and Features
    • 14.6 Known Bugs in gawk
  • 15. A Library of awk Functions
    • 15.1 Simulating gawk-specific Features
    • 15.2 Implementing nextfile as a Function
    • 15.3 Assertions
    • 15.4 Translating Between Characters and Numbers
    • 15.5 Merging an Array Into a String
    • 15.6 Turning Dates Into Timestamps
    • 15.7 Managing the Time of Day
    • 15.8 Noting Data File Boundaries
    • 15.9 Processing Command Line Options
    • 15.10 Reading the User Database
    • 15.11 Reading the Group Database
    • 15.12 Naming Library Function Global Variables
  • 16. Practical awk Programs
    • 16.1 Re-inventing Wheels for Fun and Profit
      • 16.1.1 Cutting Out Fields and Columns
      • 16.1.2 Searching for Regular Expressions in Files
      • 16.1.3 Printing Out User Information
      • 16.1.4 Splitting a Large File Into Pieces
      • 16.1.5 Duplicating Output Into Multiple Files
      • 16.1.6 Printing Non-duplicated Lines of Text
      • 16.1.7 Counting Things
    • 16.2 A Grab Bag of awk Programs
      • 16.2.1 Finding Duplicated Words in a Document
      • 16.2.2 An Alarm Clock Program
      • 16.2.3 Transliterating Characters
      • 16.2.4 Printing Mailing Labels
      • 16.2.5 Generating Word Usage Counts
      • 16.2.6 Removing Duplicates from Unsorted Text
      • 16.2.7 Extracting Programs from Texinfo Source Files
      • 16.2.8 A Simple Stream Editor
      • 16.2.9 An Easy Way to Use Library Functions
  • 17. The Evolution of the awk Language
    • 17.1 Major Changes between V7 and SVR3.1
    • 17.2 Changes between SVR3.1 and SVR4
    • 17.3 Changes between SVR4 and POSIX awk
    • 17.4 Extensions in the AT&T Bell Laboratories awk
    • 17.5 Extensions in gawk Not in POSIX awk
  • A. gawk Summary
    • A.1 Command Line Options Summary
    • A.2 Language Summary
    • A.3 Variables and Fields
      • A.3.1 Fields
      • A.3.2 Built-in Variables
      • A.3.3 Arrays
      • A.3.4 Data Types
    • A.4 Patterns
      • A.4.1 Pattern Summary
      • A.4.2 Regular Expressions
    • A.5 Actions
      • A.5.1 Operators
      • A.5.2 Control Statements
      • A.5.3 I/O Statements
      • A.5.4 printf Summary
      • A.5.5 Special File Names
      • A.5.6 Built-in Functions
      • A.5.7 Time Functions
      • A.5.8 String Constants
    • A.6 User-defined Functions
    • A.7 Historical Features
  • B. Installing gawk
    • B.1 The gawk Distribution
      • B.1.1 Getting the gawk Distribution
      • B.1.2 Extracting the Distribution
      • B.1.3 Contents of the gawk Distribution
    • B.2 Compiling and Installing gawk on Unix
      • B.2.1 Compiling gawk for Unix
      • B.2.2 The Configuration Process
    • B.3 How to Compile and Install gawk on VMS
      • B.3.1 Compiling gawk on VMS
      • B.3.2 Installing gawk on VMS
      • B.3.3 Running gawk on VMS
      • B.3.4 Building and Using gawk on VMS POSIX
    • B.4 MS-DOS and OS/2 Installation and Compilation
    • B.5 Installing gawk on the Atari ST
      • B.5.1 Compiling gawk on the Atari ST
      • B.5.2 Running gawk on the Atari ST
    • B.6 Installing gawk on an Amiga
    • B.7 Reporting Problems and Bugs
    • B.8 Other Freely Available awk Implementations
  • C. Implementation Notes
    • C.1 Downward Compatibility and Debugging
    • C.2 Making Additions to gawk
      • C.2.1 Adding New Features
      • C.2.2 Porting gawk to a New Operating System
    • C.3 Probable Future Extensions
    • C.4 Suggestions for Improvements
  • D. Glossary
  • GNU GENERAL PUBLIC LICENSE
    • Preamble
    • TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
    • How to Apply These Terms to Your New Programs
  • Index


This document was generated on 27 January 1999 using texi2html 1.55k.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026