read[int|real|string]list

Table of Contents

Prototype: readintlist(filename, comment, split, maxentries, maxbytes)
Prototype: readreallist(filename, comment, split, maxentries, maxbytes)
Prototype: readstringlist(filename, comment, split, maxentries, maxbytes)

Return type: ilist, rlist or slist

Description: Splits the file filename into separated values and returns the list.

The comment field is a multiline regular expression and will strip out unwanted patterns from the file being read, leaving unstripped characters to be split into fields. Using the empty string ("") indicates no comments.

Arguments:

  • filename : File name to read, in the range "?(/.*)
  • comment : Unanchored regex matching comments, in the range .*
  • split : Unanchored regex to split data, in the range .*
  • maxentries : Maximum number of entries to read, in the range 0,99999999999
  • maxbytes : Maximum bytes to read, in the range 0,99999999999

Example:

Prepare:

echo 1 > /tmp/cfe_list_ints
echo # Comment >> /tmp/cfe_list_ints
echo 2 >> /tmp/cfe_list_ints
echo # Another Comment >> /tmp/cfe_list_ints
echo 3 >> /tmp/cfe_list_ints
echo 1.1 > /tmp/cfe_list_reals
echo # Comment >> /tmp/cfe_list_reals
echo 2.2 >> /tmp/cfe_list_reals
echo # Another Comment >> /tmp/cfe_list_reals
echo 3 >> /tmp/cfe_list_reals
echo alpha > /tmp/cfe_list_strings
echo # Comment >> /tmp/cfe_list_strings
echo beta >> /tmp/cfe_list_strings
echo # Another Comment >> /tmp/cfe_list_strings
echo gamma >> /tmp/cfe_list_strings

Run:

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

bundle agent example
{
  vars:

      "integers" ilist => readintlist("/tmp/cfe_list_ints","#[^\n]*","[\n]",10,400);
      "strings" slist => readstringlist("/tmp/cfe_list_strings", "#[^\n]*", "\s", 10, 400);
      "reals" rlist => readreallist("/tmp/cfe_list_reals","#[^\n]*","[\n]",10,400);

  reports:

      "integers in /tmp/cfe_list_ints: $(integers)";
      "strings in /tmp/cfe_list_strings: $(strings)";
      "reals in /tmp/cfe_list_reals: $(reals)";

}

Output:

R: integers in /tmp/cfe_list_ints: 1
R: integers in /tmp/cfe_list_ints: 2
R: integers in /tmp/cfe_list_ints: 3
R: strings in /tmp/cfe_list_strings: alpha
R: strings in /tmp/cfe_list_strings: beta
R: strings in /tmp/cfe_list_strings: gamma
R: reals in /tmp/cfe_list_reals: 1.1
R: reals in /tmp/cfe_list_reals: 2.2
R: reals in /tmp/cfe_list_reals: 3