Put

Description

This command allows you to modify data at a given selector.

Dasel will create any data items that do not already exist allowing you to create entire data structures from nothing.

Usage

dasel put <type> -f <file> <selector> <value>

If --file is used without --out then the source file will be updated.

FlagDescription

<type>

The type of value you want to put.

Available arguments:

<value>

-v, --value

The value to write.

Dasel will parse this value as a string, int, or bool from this value depending on the given type.

If no -v, --value flag is given, the value is assumed to be the last argument.

This is required.

--value-file Since v1.27.0

A path to a file containing the value. If present, the contents of the file takes precedence over -v, --value.

-f, --file

Specify the file to query. This is required unless you are piping in data.

If piping in data you can optionally pass -f stdin/-f -.

-o, --out

Specify the output file. If present, results will be written to the given file. If not present, results will be written to the input file (or stdout if none given).

To force output to be written to stdout, pass -o stdoutor-o -.

-r, --read

Specify the parser to use when reading the input data.

This is required if you are piping in data, otherwise dasel will use the given file extension to guess which parser to use.

See supported file types.

-w, --write

Specify the parser to use when writing the output data.

If not provided dasel will attempt to use the --out and --read flags to determine which parser to use.

See supported file types.

-p, --parser

Shorthand for -r <value> -w <value>

-m, --multiple

Tells dasel to put multiple items.

See multiple.

-s, --selector, <selector>

Specify the selector to use. See selectors for more information.

If no selector flag is given, dasel assumes the first argument given is the selector.

This is required.

--plain

By default, dasel formats the output using the specified parser.

If this flag is used no formatting occurs and the results output as a string.

-c, --compact

This tells dasel to output compact data where possible. E.g. not pretty printing JSON.

--merge-input-documents

--escape-html

Example

Put string

$ echo "name: Tom" | ./dasel put string -p yaml ".name" Jim
name: Jim

Create documents from scratch

You can pipe multiple dasel commands together in order to build entire documents or make multiple changes:

$ echo '' |
dasel put string -p yaml '.servers.[].bind_dn' 'x' |
dasel put string -p yaml -m '.servers.[*].attributes.name' 'y' |
dasel put string -p yaml -m '.servers.[*].group_mappings.[].group_dn' 'a' |
dasel put string -p yaml -m '.servers.[*].group_mappings.[].group_dn' 'b'
servers:
  - attributes:
      name: "y"
    bind_dn: x
    group_mappings:
      - group_dn: a
      - group_dn: b

Last updated