Post

How to detect duplicates using jq

Practical guide: how to detect duplicates using jq.

This command detects duplicate entries in a YAML array using yq and jq. It converts the YAML to JSON, groups array elements, and filters for groups with more than one member. This is useful for catching accidental duplicates in configuration files such as LDAP group memberships.

1
2
yq -o=json eval  data/aaa/bbb.yaml | jq '.ldap.ldap.members  | group_by(.) | map(select(length>1) | .[0])'

This post is licensed under CC BY 4.0 by the author.