Skip to content

Merge two yaml file selecting keys using wildcard character and removing duplicates #1717

@Galileo1

Description

@Galileo1

I want to merge two yaml files using yq in bash script.Selecting only specific keys values , removing duplicates and building a string.

file1.yaml

FT1: true
FT2: true

file2.yaml

FT1: false
FT2: false
FT3: false
FT4: false
Blah1: abc
Blah2: efg

Desired Output:

Trying to build a command like below.

  • Filter any keys that starts with (FT*)
  • join the key=values
  • removing FT1, FT2 from file2.yaml
  • And building a command for each key=value pair appending it with --from-literal=

--from-literal=FT1=true --from-literal=FT2=true --from-literal=FT3=false --from-literal=FT4=false

What I have tried so far:
yq eval '. | to_entries| .[] | select(.key == "FT*") | [.key, .value] | join("=") file1.yaml

The above command output is as below. Not sure how to merge them , remove duplicates from file2 and build the command.

file1.yaml
FT1=true FT2=true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions