Grok syntax guideThe essentialsStatements and expressions. A Grok program consists of a sequence of statements and/or expressions. Statements are executed for their side effects, typically changing the value of a variable, printing something to the screen, etc. Expressions typically produce no side effects; instead, they are evaluated and the results of evaluation are printed to standard output (which is typically the screen, unless the output has been redirected). Grok does not have semicolons at the end of its statements. Variables and types. There is no need to declare
variables in Grok. A variable is automatically created when it is first
assigned to.
In Grok there are three basic types: strings (including numbers), relations
and sets.
Parameters. Grok scripts can take command-line parameters. The parameters can be accessed through the variables $0, $1, $2, and so on. $0 holds the name of the Grok script being executed, $1 holds the first parameter, $2 holds the second parameter, and so on. Assignment statementsAssignment statements. The assignment statements in Grok have the general form of:
Flow control statementsIf statement. The if statement in Grok has the general form of:
Loop statement. The loop statement in Grok looks as follows:
For statement. The for loop in Grok looks as follows:
|