Chapter 12. The gawk Pattern Processing Language

 < Day Day Up > 

Chapter 12. The gawk Pattern Processing Language

IN THIS CHAPTER

Syntax 528

Arguments 528

Options 529

Patterns 530

Actions 531

Variables 531

Functions 532

Associative Arrays 534

Control Structures 535

Examples 537

getline: Controlling Input 554

Coprocess: Two-Way I/O 557

Getting Input from a Network 558

Error Messages 559

The gawk (GNU 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 gawk language is data driven: You describe the data you want to work with and tell gawk what to do with the data once it finds it.

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

The gawk 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

  • Coprocess execution

  • Network data exchange

     < Day Day Up > 


    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    A Practical Guide to LinuxR Commands, Editors, and Shell Programming
    ISBN: 131478230
    EAN: N/A
    Year: 2005
    Pages: 213

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