join

Table of Contents

Prototype: join(glue, list)

Return type: string

Description: Join the items of list into a string, using the conjunction in glue.

Converts a list or data container into a scalar variable using the join string in first argument.

Arguments:

  • glue: string, in the range: .*
  • list: string, in the range: [a-zA-Z0-9_$(){}\[\].:]+

Example:

body common control
{
      bundlesequence => { "test" };
}

bundle agent test
{
  vars:

      "mylist" slist => { "one", "two", "three", "four", "five" };
      "datalist" data => parsejson('[1,2,3,
                        "one", "two", "three",
                        "long string",
                        "four", "fix", "six",
                        "one", "two", "three",]');

      "mylist_str" string => format("%S", mylist);
      "datalist_str" string => format("%S", datalist);
      "myscalar" string => join("->", mylist);
      "datascalar" string => join("->", datalist);

  reports:
      "Concatenated $(mylist_str): $(myscalar)";
      "Concatenated $(datalist_str): $(datascalar)";
}

Output:

R: Concatenated { "one", "two", "three", "four", "five" }: one->two->three->four->five
R: Concatenated [1,2,3,"one","two","three","long string","four","fix","six","one","two","three"]: 1->2->3->one->two->three->long string->four->fix->six->one->two->three