Ensure (first field) musician name definition in a csv sheet music

body common control
{
  any::
    bundlesequence  => { prepare("musician_name") };
    inputs          => { "/var/cfengine/inputs/libraries/cfengine_stdlib.cf" };
}

bundle agent prepare(musician) 
{
  vars:
    "sheet" slist => { "/tmp/sheet" };

  files:
    "$(sheet)"
      create => "true",
      copy_from => no_backup_cp("$(sheet).orig"),
      edit_line => prefix_lines_matching("^(?!$(musician);|(\s*#)).*", "$(musician);");
}

bundle edit_line prefix_lines_matching(regex,prefix)

 # Prefix lines of a file matching a regex

{
replace_patterns:

 "^($(regex))$"

     replace_with => prefix("$(prefix)"),
     comment => "Search and replace string";
}

body replace_with prefix(p)
{
replace_value => "$(p)$(match.1)";
occurrences => "all";
}

Example :

# cat /tmp/sheet.orig
instrument1;file1;k1=v11,k2=v21
instrument2;file1;k1=v11

# cf-agent -I -f ./test.cf
 -> Updated /tmp/sheet from source /tmp/sheet.orig on localhost
 -> Edited file /tmp/sheet

# cat /tmp/sheet
musician_name;instrument1;file1;k1=v11,k2=v21
musician_name;instrument2;file1;k1=v11

# cf-agent -I -f ./test.cf