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.

Table 2. The Order of Operations for awk (continued)<br />

Operators Order of operations<br />

A || B Logical OR<br />

A ? B : C Conditional expression<br />

V=B V+=B V-=B V*=B V/=B V%=B V^=B Assignment<br />

Notes:<br />

1. A, B, C are any expression.<br />

2. i is any expression yielding an integer.<br />

3. V is any variable.<br />

<strong>Command</strong>-line arguments<br />

awk sets the built-in variable ARGC to the number of command-line arguments.<br />

The built-in array ARGV has elements subscripted with digits from zero to ARGC−1,<br />

giving command-line arguments in the order they appeared on the command line.<br />

The ARGC count and the ARGV vector do not include command-line options<br />

(beginning with -) or the program file (following –f). They do include the name of<br />

the command itself, initialization statements of the form var=value, and the names<br />

of input data files.<br />

awk actually creates ARGC and ARGV before doing anything else. It then “walks<br />

through” ARGV, processing the arguments. If an element of ARGV is an empty<br />

string, awk skips it. If it contains an equals sign (=), awk interprets it as a variable<br />

assignment. If it is a minus sign (−), awk immediately reads input from stdin until it<br />

encounters the end of the file. Otherwise, awk treats the argument as a filename<br />

and reads input from that file until it reaches the end of the file.<br />

Note: awk runs the program by “walking through” ARGV in this way; thus, if the<br />

program changes ARGV, awk can read different files and make different<br />

assignments.<br />

Input<br />

awk divides input into records. A record separator character separates each record<br />

from the next. The value of the built-in variable RS gives the current record<br />

separator character; by default, it begins as the newline (\n). If you assign a<br />

different character to RS, awk uses that as the record separator character from that<br />

point on.<br />

awk divides records into fields. A field separator string, given by the value of the<br />

built-in variable FS, separates each field from the next. You can set a specific<br />

separator string by assigning a value to FS, or by specifying the –F ere option on<br />

the command line. You can assign a regular expression to FS. For example:<br />

FS = "[,:$]"<br />

says that commas, colons, or dollar signs can separate fields. As a special case,<br />

assigning FS a string containing only a blank character sets the field separator to<br />

white space. In this case, awk considers any sequence of contiguous space or tab<br />

characters a single field separator. This is the default for FS. However, if you assign<br />

FS a string containing any other character, that character designates the start of a<br />

new field. For example, if we set FS=\t (the tab character),<br />

texta \t textb \t \t \t textc<br />

awk<br />

Chapter 2. Shell command descriptions 37

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

Saved successfully!

Ooh no, something went wrong!