format()

Returns a new string created using given arguments.

Syntax

format(STR_FMT, PARAM[, ...])
format(STR_FMT, ARRAY_EXPR)
Required Parameter
STR_FMT

Format string including the format specifier.

For available format specifiers, refer to the Class Formatter document at the following address: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Formatter.html

PARAM, ... or ARRAY_EXPR

Input value to be represented in a specified format. You can use an expression that returns an array (such as an expression that uses array() and groups()) to return the arguments to be applied to the format string.

Usage

json "{}" 
| eval str=format("date: %04d-%02d-%02d", 2004, 3, 29)
  => "date: 2004-03-29"

json "{}"  
| eval  str=format("%3$s-%1$s-%2$s", groups("Mar 29 2004", "(.*?) (.*?) (.*)"))
  => "2004-Mar-29"