Browse Prior Art Database

Awk -- A Pattern Scanning and Processing Language

IP.com Disclosure Number: IPCOM000128815D
Original Publication Date: 1978-Jul-31
Included in the Prior Art Database: 2005-Sep-19
Document File: 12 page(s) / 46K

Publishing Venue

Software Patent Institute

Related People

Alfred V. Aho: AUTHOR [+3]

Abstract

Awk is a programming language whose basic operation is to search a set of files for patterns, and to perform specified actions upon lines or fields of lines which contain instances of those patterns. Awk makes certain data selection and transformation operations easy to express; for example, the awk program length > 72 prints all input lines whose length exceeds 72 characters; the program NF % 2 = = O prints all lines with an even number of fields; and the program {$1 = log($1); print} replaces the first field of each line by its logarithm.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 13% of the total text.

Page 1 of 12

THIS DOCUMENT IS AN APPROXIMATE REPRESENTATION OF THE ORIGINAL.

Awk -- A Pattern Scanning and Processing Language

Alfred V. Aho

Brian W Kernighan

Perer J. Weinberger

Awk -- A Pattern Scanning and Processing Language

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

ABSTRACT

Awk is a programming language whose basic operation is to search a set of files for patterns, and to perform specified actions upon lines or fields of lines which contain instances of those patterns. Awk makes certain data selection and transformation operations easy to express; for example, the awk program length > 72 prints all input lines whose length exceeds 72 characters; the program NF % 2 = = O prints all lines with an even number of fields; and the program {$1 = log($1); print} replaces the first field of each line by its logarithm.

Awk patterns may include arbitrary boolean combinations of regular expressions and of relational operators on strings, numbers, fields, variables, and array elements. Actions may include the same pattern-matching constructions as in patterns, as well as arithmetic and string expressions and assignments, if- else, while, for statements, and multiple output streams.

This report contains a user's guide, a discussion of the design and implementation, and some timing statistics.

July 31, 1978

Awk - A Pattern Scanning and Processing Language

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

Bell Laboratories Page 1 Jul 31, 1978

Page 2 of 12

Awk -- A Pattern Scanning and Processing Language

[ Chapter ] 1. Introduction

Awk is a programming language designed to make many common information retrieval and text manipulation tasks easy to state and to perform.

The basic operation of awk is to scan a set of input lines in order, searching for lines which match any of a set of patterns which the user has specified. For each pattern, an action can be specified; this action will be performed on each line that matches the pattern.

Readers familiar with the UNIX1 program grep2 will recognize the approach, although in awk the patterns may be more general than in grep, and the actions allowed are more involved than merely printing the matching line. For example, the awk program

     {print $3, $2} prints the third and second columns of a table in that order. The program

     $2 ~ /A|B|C/ prints all input lines with an A, B, or C in the second field. The program

     $1 ! = prev {print; prev = $1} prints all lines in which the first field is different from the previous first field.

1.1. Usage

The command awk program [ files ] executes the awk commands in the string program on the set of named files, or on the standard input if there are no files. The statements can also be placed in a file pfile, and executed by the command awk f pfile [ files ]

1.2. Program Structure

An awk program is a sequence of statements of the form: pattern {action} pattern {action}

Each line of input is marched against each of the patterns in turn. For each pattern that matches,...