Forrest logo
back to the yq tool

yq:tldr:7aa22

yq: Merge two files and print to `stdout` (v4+).
$ yq eval-all 'select(filename == "${filename1-yaml}") * select(filename == "${filename2-yaml}")' ${filename1-yaml} ${filename2-yaml}
try on your machine

This command is using the yq tool to evaluate and filter data from two YAML files based on a specific condition.

Here is the breakdown of the command:

  1. yq eval-all: This command instructs yq to evaluate multiple expressions on multiple documents and merge the results.

  2. 'select(filename == "${filename1-yaml}") * select(filename == "${filename2-yaml}")': This is the expression that will be evaluated by yq. It consists of two parts separated by *:

    • select(filename == "${filename1-yaml}"): This selects all documents in the YAML file with a filename equal to the value of the environment variable filename1-yaml.

    • select(filename == "${filename2-yaml}"): This selects all documents in the YAML file with a filename equal to the value of the environment variable filename2-yaml.

    The expressions inside select() are used to filter the documents based on the specified condition.

  3. ${filename1-yaml} ${filename2-yaml}: These are the input files (YAML files) that will be processed by yq. The values of the environment variables filename1-yaml and filename2-yaml will be substituted here.

In summary, the command evaluates both input YAML files and selects documents from each file that have filenames matching the values of filename1-yaml and filename2-yaml. The merged results will be printed as the output.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the yq tool