Chapter 14. The awk Pattern Processing Language


Chapter 14. The awk Pattern Processing Language

IN THIS CHAPTER

Syntax

610

Arguments

610

Options

611

Patterns

612

Actions

612

Variables

613

Functions

614

Associative Arrays

615

Control Structures

616

Examples

618

getline: Controlling Input

634

Error Messages

637


The awk utility is a pattern-scanning and processing language that searches one or more files to see whether they contain records (usually lines) that match specified patterns. It processes lines by performing actions, such as writing the record to standard output or incrementing a counter, each time it finds a match. As opposed to procedural languages, the awk language is data driven: You describe the data you want to work with and tell awk what to do with the data once it finds it.

You can use awk to generate reports or filter text. It works equally well with numbers and text; when you mix the two, awk usually comes up with the right answer. The authors of awk (Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan) designed the original utility to be easy to use. To achieve this end they sacrificed execution speed.

The awk utility takes many of its constructs from the C programming language. It includes the following features:

  • Flexible format

  • Conditional execution

  • Looping statements

  • Numeric variables

  • String variables

  • Regular expressions

  • Relational expressions

  • C's printf




A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net