Skip to content

generate

Execute an expression for each record to generate new records.

Synopsis

bash
recs generate [options] <expression> [files...]

Description

Execute an expression for each record to generate new records. The expression should return an array of new record objects (or a single record). Each generated record gets a chain link back to the original input record under the '_chain' key (configurable via --keychain). With --shell, the expression is executed as a shell command and each line of stdout is parsed as a JSON record. Use {{keyspec}} for template interpolation from the input record in shell commands.

Options

FlagDescription
--keychain <name>Key name for the chain link back to the original record. Default is '_chain'. May be a key spec.
--passthroughEmit the input record in addition to the generated records.
--shellExecute the expression as a shell command instead of a code snippet. Each line of stdout is parsed as a JSON record. Use {{keyspec}} for template interpolation from the input record.
--expr / -e <code>Inline code snippet (alternative to positional argument).
--snippet-file / -E <path>Read snippet code from a file instead of the command line.
--lang / -l <lang>Snippet language: js (default), python/py, perl/pl.

Examples

Generate sub-records from a feed and chain back to the original

bash
recs generate 'fetchFeed(r.url).map(item => ({ title: item.title }))'

Execute a shell command to generate JSON records

bash
recs generate --shell 'echo {"x": 1}'

Shell command with template interpolation from input record

bash
recs generate --shell 'echo {"name": "{{name}}"}'

See Also

Released under the MIT License.