General Syntax for Eval

The eval operator displays events after evaluating the result of the specified function. Eval operators use the following syntax formats:

| eval newField = expression
EXPRESSION Evaluation of values(fields) or constants with operators

where

Functions that can be used with the eval operator include:

concat, tonumber, tostring, replace(X,Y,Z), abs(X), case(X,"Y",...), ceil(X), ceiling(X), exp(X), floor(X), if(X,Y,Z), isfalse(X), istrue(X), len(X), ln(X), log(X), lower(X), tolower(X), mod(x,y), rand(), round(X), sqrt(X), substr(X,Y,Z), sum(x,y,z,…), trim(X), ltrim(X), rtrim(X), upper(X)toupper(X), urldecode(X).

Aliases that contain special characters have the following syntax restrictions:

Special Characters Restrictions Examples
&, !, - , = , % , <, >, | Need to be enclosed in single/double quotes when they are reused and the search works as expected. | rename Name as 'DP-V' | eval test = tostring ( "DP-V" )
@, #, +, ?, /, ^, [], {}, _ , *, ~, . $, % Do not need to be enclosed in single/double quotes when they are reused and the search runs as expected. | rename Name as 'DP@V' | eval test = tostring ( DP@V )
\

When a backslash is used in an alias name, add an additional backslash \ to escape the character. It does not need to be enclosed in single/double quotes when it is reused and the search runs as expected.

The outcome field name should show only one backslash.

... | rename Name as 'DP\\V' | eval test = tostring ( DP\\V )

 

For more information about eval functions, see Understand Eval Functions.

Considerations for Using Eval Functions

Please be aware of the following considerations when using the eval functions:

Examples

Pipeline operators, such as eval, can use operator chaining to allow output from one pipe operator to be used as input to a subsequent one.

Restrictions

Some functions have restrictions based on the data type:

The following expression is not allowed because two different data types (Name and 1) are not allowed in an arithmetic operation.

... | eval test1 = Name + 1 

The expression below is not allowed because replace expects string data types for parameters.

... | eval test1 = Name and replace ( 1 , Name , Name ) 

 

For more information about syntax requirements that the query must meet, see Understand the Query Syntax.