Полезная информация

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 11.5 OperatorsChapter 11
The Awk Scripting Language
Next: 11.7 Group Listing of Awk Commands
 

11.6 Variables and Array Assignments

Variables can be assigned a value with an = sign. For example:

FS = ","

Expressions using the operators +, -, /, and % (modulo) can be assigned to variables.

Arrays can be created with the split function (see below), or they can simply be named in an assignment statement. ++, +=, and -= are used to increment or decrement an array, as in the C language. Array elements can be subscripted with numbers (array[1], ..., array[n]) or with names. For example, to count the number of occurrences of a pattern, you could use the following script:

/pattern/ { array["/pattern/"]++ }
END { print array["/pattern/"] }


Previous: 11.5 OperatorsUNIX in a Nutshell: System V EditionNext: 11.7 Group Listing of Awk Commands
11.5 OperatorsBook Index11.7 Group Listing of Awk Commands

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System