Prototype: countlinesmatching(regex, filename)

Return type: int

Description: Count the number of lines in file filename matching regex.

This function matches lines in the named file, using an anchored regular expression that should match the whole line, and returns the number of lines matched.

Arguments:

  • regex: regular expression - Regular expression - in the range: .*
  • filename: string - Filename - in the range: "?(/.*)

Example:

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

bundle agent example
{
  vars:
      # typically there is only one root user
      "no" int => countlinesmatching("root:.*","/etc/passwd");

  reports:
      "Found $(no) lines matching";
}

Output:

code
R: Found 1 lines matching