home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 11.5 Operators Chapter 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 Operators UNIX in a Nutshell: System V Edition Next: 11.7 Group Listing of Awk Commands
11.5 Operators Book Index 11.7 Group Listing of Awk Commands

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