21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

iv<strong>G<strong>AWK</strong></strong>: <strong>Effective</strong> <strong>AWK</strong> <strong>Programming</strong>5 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755.1 Constant Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755.1.1 Numeric and String Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . 755.1.2 Octal and Hexadecimal Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 755.1.3 Regular Expression Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765.2 Using Regular Expression Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . 765.3 Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.3.1 Using Variables in a Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.3.2 Assigning Variables on the Command Line. . . . . . . . . . . . . . . . 785.4 Conversion of Strings and Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . 795.5 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815.6 String Concatenation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825.7 Assignment Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835.8 Increment and Decrement Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 865.9 True and False in awk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875.10 Variable Typing and Comparison Expressions . . . . . . . . . . . . . . . . 875.10.1 String Type Versus Numeric Type . . . . . . . . . . . . . . . . . . . . . . . 885.10.2 Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895.11 Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915.12 Conditional Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925.13 Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935.14 Operator Precedence (How Operators Nest) . . . . . . . . . . . . . . . . . . 946 Patterns, Actions, and Variables . . . . . . . . . . . . . 966.1 Pattern Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966.1.1 Regular Expressions as Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . 966.1.2 Expressions as Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966.1.3 Specifying Record Ranges with Patterns . . . . . . . . . . . . . . . . . . 986.1.4 The BEGIN and END Special Patterns . . . . . . . . . . . . . . . . . . . . . . 996.1.4.1 Startup and Cleanup Actions . . . . . . . . . . . . . . . . . . . . . . . . 996.1.4.2 Input/Output from BEGIN and END Rules . . . . . . . . . . . 1006.1.5 The Empty Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.2 Using Shell Variables in Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006.3 Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016.4 Control Statements in Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026.4.1 The if-else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026.4.2 The while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1036.4.3 The do-while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.4.4 The for Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046.4.5 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056.4.6 The break Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066.4.7 The continue Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076.4.8 The next Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086.4.9 Using gawk’s nextfile Statement . . . . . . . . . . . . . . . . . . . . . . . 1096.4.10 The exit Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.5 Built-in Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1106.5.1 Built-in Variables That Control awk . . . . . . . . . . . . . . . . . . . . . 1106.5.2 Built-in Variables That Convey Information . . . . . . . . . . . . . 113

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

Saved successfully!

Ooh no, something went wrong!