Skip to content

How to merge two slists and remove duplicate entries? #4473

Answered by olehermanse
craigcomstock asked this question in Q&A
Discussion options

You must be logged in to vote

Using the return value of mergedata() directly, as an argument to unique() works:

bundle agent main
{
  vars:
    "list1"
      slist => { "one", "two" };
    "list2"
      slist => { "one", "three" };
    "result"
      slist => unique(mergedata(list1, list2));

  reports:
    "result is $(with)" with => storejson("result");
}

(I like to not quote string args like list1 and list2, to hint that they are variables, and not just string values. To CFEngine it doesn't really matter).

Output:

$ cf-agent -K test.cf
R: result is [
  "one",
  "two",
  "three"
]

More information in the docs:

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by craigcomstock
Comment options

You must be logged in to vote
6 replies
@craigcomstock
Comment options

@craigcomstock
Comment options

@tzz
Comment options

@olehermanse
Comment options

@tzz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants