16.12.2012 Views

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

|<br />

|<br />

|<br />

Files that you specify on the command line with the file argument provide the input<br />

data for awk to manipulate. If you specify no files or you specify a dash (–) as a<br />

file, awk reads data from standard input (stdin).<br />

You can initialize variables on the command line using:<br />

var=value<br />

You can intersperse such initializations with the names of input files on the<br />

command line. awk processes initializations and input files in the order they appear<br />

on the command line. For example, the command:<br />

awk -f progfile a=1 f1 f2 a=2 f3<br />

sets a to 1 before reading input from f1 and sets a to 2 before reading input from f3.<br />

Variable initializations that appear before the first file on the command line are<br />

performed immediately after the BEGIN action. Initializations appearing after the<br />

last file are performed immediately before the END action. For more information on<br />

BEGIN and END, see Patterns.<br />

The –v option lets you assign a value to a variable before the awk program begins<br />

execution (that is, before the BEGIN action). For example, in:<br />

awk -v v1=10 -f prog datafile<br />

awk assigns the variable v1 its value before the BEGIN action of the program (but<br />

after default assignments made to such built-in variables as FS and OFMT; these<br />

built-in variables have special meaning to awk, as described later).<br />

awk divides input into records. By default, newline characters separate records;<br />

however, you can specify a different record separator if you want.<br />

One at a time, and in order, awk compares each input record with the pattern of<br />

every rule in the program. When a pattern matches, awk performs the action part of<br />

the rule on that input record. Patterns and actions often refer to separate fields<br />

within a record. By default, white space (usually blanks, newlines, or horizontal tab<br />

characters) separates fields; however, you can specify a different field separator<br />

string using the –F ere option).<br />

You can omit the pattern or action part of an awk rule (but not both). If you omit<br />

pattern, awk performs the action on every input record (that is, every record<br />

matches). If you omit action, awk's default action is equivalent to: {print}.<br />

awk considers everything after a # in a program line to be a comment. For<br />

example:<br />

# This is a comment<br />

To continue program lines on the next line, add a backslash (\) to the end of the<br />

line. Statement lines ending with a comma (,), double or-bars (||), or double<br />

ampersands (&&) continue automatically on the next line.<br />

Variables and expressions<br />

There are three types of variables in awk: identifiers, fields, and array elements.<br />

An identifier is a sequence of letters, digits, and underscores beginning with a letter<br />

or an underscore. These characters must be from the P<strong>OS</strong>IX portable character<br />

set. (Data can come from other character sets.)<br />

awk<br />

Chapter 2. Shell command descriptions 33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!