Blockinfile

The blockinfile function allows you to insert, update, or remove a block of multi-line text in a file. The block is surrounded by customizable markers to define its boundaries.

Options:

  • block: The multi-line text block to be inserted or updated.
  • insertafter: A pattern to insert the block after.
  • insertbefore: A pattern to insert the block before.
  • marker: The marker template with "{mark}" as a placeholder.
  • markerbegin: The text to replace "{mark}" for the beginning marker.
  • markerend: The text to replace "{mark}" for the ending marker.
  • state: A boolean to indicate whether to insert/update (true) or remove (false) the block.
  • backup: A boolean to indicate whether to create a backup of the file.
  • create: A boolean to indicate whether to create the file if it does not exist.

Example usage:


  Blockinfile({
    Insertafter = "pattern to insert after",
    Insertbefore = "pattern to insert before",
    Marker = "# {mark}",
    Markerbegin = "BEGIN GLUE CUSTOM BLOCK",
    Markerend = "END GLUE CUSTOM BLOCK",
    State = true,
    Backup = true,
    Create = true,
    Block = [[
      This is a block of text
      that spans multiple lines.
    ]],
  })