
format
Description
This command is used implicitly by subsearches. This command takes the results of a subsearch, formats the results into a single result and places that result into a new field called search
.
Syntax
format [mvsep="<mv separator>"] [maxresults=<int>] ["<row prefix>" "<column prefix>" "<column separator>" "<column end>" "<row separator>" "<row end>"]
If you want to specify a row or column options, you must specify all of the row and column options.
Optional arguments
- mvsep
- Syntax: mvsep="<string>"
- Description: The separator to use for multivalue fields.
- Default: OR
- maxresults
- Syntax: maxresults=<int>
- Description: The maximum results to return.
- Default: 0, which means no limitation on the number of results returned.
- <row prefix>
- Syntax: "<string>"
- Description: The value to use for the row prefix.
- Default: The open parenthesis character "("
- <column prefix>
- Syntax: "<string>"
- Description: The value to use for the column prefix.
- Default: The open parenthesis character "("
- <column separator>
- Syntax: "<string>"
- Description: The value to use for the column separator.
- Default: AND
- <column end>
- Syntax: "<string>"
- Description: The value to use for the column end.
- Default: The close parenthesis character ")"
- <row separator>
- Syntax: "<string>"
- Description: The value to use for the row separator.
- Default: OR
- <row end>
- Syntax: "<string>"
- Description: The value to use for the column end.
- Default: The close parenthesis character ")"
Usage
By default, when you do not specify any of the optional row and column arguments, the output of the format
command defaults to: "(" "(" "AND" ")" "OR" ")"
.
Specifying row and column arguments
There are several reasons to specify the row and column arguments:
- Subsearches
- There is an implicit
format
at the end of a subsearch that uses the default values for column and row arguments. For example, you can specify OR for the column separator by including theformat
command at the end of the subsearch.
- Export the search to a different system
- Specify the row and column arguments when you need to export the search to another system that requires different formatting.
Examples
1. Example with no optional parameters
Suppose that you have results that look like this:
source | sourcetype | host |
---|---|---|
syslog.log | syslog | my_laptop |
bob-syslog.log | syslog | bobs_laptop |
laura-syslog.log | syslog | lauras_laptop |
The following search returns the top 2 results, and creates a search based on the host, source, and sourcetype fields. The default format settings are used.
... | head 2 | fields source, sourcetype, host | format
This search returns the syntax for a search that is based on the field values in the top 2 results. The syntax is placed into a new field called search.
source | sourcetype | host | search |
---|---|---|---|
( ( host="mylaptop" AND source="syslog.log" AND sourcetype="syslog" ) OR ( host="bobslaptop" AND source="bob-syslog.log" AND sourcetype="syslog" ) ) |
2. Example using the optional parameters
You want to produce output that is formatted to use on an external system.
... | format "[" "[" "&&" "]" "||" "]"
Using the data in Example 1, the result is:
source | sourcetype | host | search |
---|---|---|---|
[ [ host="mylaptop" && source="syslog.log" && sourcetype="syslog" ] | | [ host="bobslaptop" && source="bob-syslog.log" && sourcetype="syslog" ] ] |
3. Multivalue separator example
The following search uses the eval
command to create a field called "foo" that contains one value "eventtype,log_level". The makemv
command is used to make the foo field a mulitvalue field and specifies the comma as the delimiter between the values. The search then outputs only the foo field and formats that field.
index=_internal |head 1 |eval foo="eventtype,log_level" | makemv delim="," foo | fields foo | format mvsep="mvseparator" "{" "[" "AND" "]" "AND" "}"
This results in the following output:
foo | search |
---|---|
[ ( foo="eventtype" mvseparator foo="log_level" ) ] } |
See also
PREVIOUS foreach |
NEXT gauge |
This documentation applies to the following versions of Splunk® Enterprise: 6.3.0, 6.3.1, 6.3.2, 6.3.3, 6.3.4, 6.3.5, 6.3.6, 6.3.7, 6.3.8, 6.3.9, 6.3.10, 6.3.11, 6.3.12, 6.3.13, 6.3.14, 6.4.0, 6.4.1, 6.4.2, 6.4.3, 6.4.4, 6.4.5, 6.4.6, 6.4.7, 6.4.8, 6.4.9, 6.4.10, 6.4.11, 6.5.0, 6.5.1, 6.5.2, 6.5.3, 6.5.4, 6.5.5, 6.5.6, 6.5.7, 6.5.8, 6.5.9, 6.5.10, 6.6.0, 6.6.1, 6.6.2, 6.6.3, 6.6.4, 6.6.5, 6.6.6, 6.6.7, 6.6.8, 6.6.9, 6.6.10, 6.6.11, 6.6.12, 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.0.5, 7.0.9, 7.0.10, 7.0.11, 7.0.13, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9, 7.1.10, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 7.2.10, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.3.6, 7.3.7, 7.3.8, 7.3.9, 8.0.0, 8.0.1, 8.0.2, 8.0.3, 8.0.4, 8.0.5, 8.0.6, 8.0.7, 8.0.8, 8.0.9, 8.1.0, 8.1.1, 8.1.2, 8.1.3, 7.0.4, 7.0.6, 7.0.7, 7.0.8
Feedback submitted, thanks!