The AWK Programming Language

Alfred V. Aho, Peter J. Weinberger, Brian W. Kernighan

Publisher: Addison-Wesley, 1988, 210 pages

ISBN: 0-201-07981-X

Keywords: Programming

Last modified: May 26, 2021, 11:21 p.m.

Originally developed by Alfred Aho, Brian Kernighan, and Peter Weinberger in 1977, AWK is a pattern-matching language for writing short programs to perform common data-manipulation tasks. In 1985, a new version of the language was developed, incorporating additional features such as multiple input files, dynamic regular expressions, and user-defined functions. This new version is available for both UNIX and MS-DOS.

This is the first book on AWK. It begins with a tutorial that shows how easy AWK is to use. The tutorial is followed by a comprehensive manual for the new version of AWK.

Subsequent chapters illustrate the language by a range of useful applications, such as:

  • Retrieving, transforming, reducing, and validating dtata
  • Managing small, personal databases
  • Text processing
  • Little languages
  • Experimenting with algorithms

The examples illustrate the book's three themes: showing how to use AWK well, demonstrating AWK's versatility, and explaining how common computing operations are done. In addition, the book contains two appendixes: a summary of the language, and answers to selected exercises.

  1. An AWK Tutorial
    1. Getting Started
      • The Structure of an AWK Program
      • Running an AWK Program
      • Errors
    2. Simple Output
      • Printing Every Line
      • Printing Certain Fields
      • NF, the Number of Fields
      • Computing and Printing
      • Printing Line Numbers
      • Putting Text in the Output
    3. Fancier Output
      • Lining Up Fields
      • Sorting the Output
    4. Selection
      • Selection by Comparison
      • Selection by Computation
      • Selection by Text Content
      • Combination of Patterns
      • Data Validation
      • BEGIN and END
    5. Computing with AWK
      • Counting
      • Computing Sums and Averages
      • Handling Text
      • String Concatenation
      • Printing the Last Input Line
      • Built-in Functions
      • Counting Lines, Words, and Characters
    6. Control-Flow Statements
      • If-Else Statement
      • While Statement
      • For Statement
    7. Arrays
    8. A Handful of Useful "One-liners"
    9. What Next?
  2. The AWK Language
      • The Input File Countries
      • Program Format
    1. Patterns
      • BEGIN and END
      • Expressions as Patterns
      • String-Matching Patters
      • Regular Expressions
      • Compound Patterns
      • Range Patterns
      • Summary of Patterns
    2. Actions
      • Expressions
      • Control-Flow Statements
      • Empty Statements
      • Arrays
    3. User-Defined Functions
    4. Output
      • The print statement
      • Output Separators
      • The printf statement
      • Output into Files
      • Output into Pipes
      • Closing Files and Pipes
    5. Input
      • Input Separators
      • Multiline Records
      • The getline Function
      • Command-Line Variable Assignments
      • Command-Line Arguments
    6. Interaction with Other Programs
      • The system Function
      • Making a Shell Command from an AWK Program
    7. Summary
  3. Data Processing
    1. Data Transformation and Reduction
      • Summing Columns
      • Computing Percentages and Quantiles
      • Number with Commas
      • Fixed-Field Input
      • Program Cross-Reference Checking
      • Formatted Output
    2. Data Validation
      • Balanced Delimiters
      • Password-File Checking
      • Generating Data-Validation Programs
      • Which Version of AWK?
    3. Bundle and Unbundle
    4. Multiline Records
      • Records Separated by Blank Lines
      • Processing Multiline Records
      • Records witth Headers and Trailers
      • Name-Value Data
    5. Summary
  4. Reports and Databases
    1. Generating Reports
      • A Simple Report
      • A More Complex Report
    2. Packaged Queries and Reports
      • Form Letters
    3. A Relational Database System
      • Natural Joins
      • The relfile
      • q, and awk-like query language
      • qawk, a q-to-awk translator
    4. Summary
  5. Processing Words
    1. Random Text Generation
      • Random Choices
      • Cliche Generation
      • Random Sentences
    2. Interactive Text Manipulation
      • Skills Testing: Arithmetic
      • Skills Testing: Quiz
    3. Text Processing
      • Word Counts
      • Text Formatting
      • Maintaining Cross-References in Manuscripts
      • Making a KWIC Index
      • Making Indexes
    4. Summary
  6. Little Languages
    1. An Assembler and Interpreter
    2. A Language for Drawing Graphs
    3. A Sort Generator
    4. A Reverse-Polish Calculator
    5. An Infix Calculator
    6. Recursive-Descent Parsing
    7. Summary
  7. Experiments with Algorithms
    1. Sorting
      • Insertion Sort
      • Quicksort
      • Heapsort
    2. Profiling
    3. Topological Sorting
      • Breadth-First Topological Sort
      • Depth-First Search
      • Depth-First Topological Sort
    4. Make: A File Updating Program
    5. Summary
  8. Epilog
    1. AWK as a Language
    2. Performance
    3. Conclusion
  1. AWK Summary
  2. Answers to Selected Exercises

Reviews

The AWK Programming Language

Reviewed by Roland Buresund

Very Good ******** (8 out of 10)

Last modified: May 21, 2007, 3:25 a.m.

Check the authors and you'll understand where it got its name from. The defining document for AWK.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required