csvplate

command module
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

csvplate

csvplate is a command-line utility that turns rows from a CSV file into rendered Go templates. You can generate a single aggregated output or one file per row.

Usage

> csvplate -h
csvplate (version: --): a CSV templated file generator

Usage: csvplate [options]
Options:
  -i, --csv string        Path to input CSV file, or the CSV content itself
  -t, --template string   Path to Go template file, or the template content itself
  -o, --out string        Output file path (may include template expressions)
  -c, --counter string    The field name to use for the row counter (default "_index_")
  -n, --noheader          Treat CSV as having no header row
  -s, --skip string       Number of lines to skip or regex to match the first (header) line
  -f, --force             Overwrite existing output files
  -d, --csv-sep string    CSV field separator (default ",")

Mode of operation:
  If the output file name contains template expressions ({{...}}), one file per row
  will be created, else a single file will be created with all rows.    
  In single file mode, the dot (.) in the template is a slice of objects (one per row).
  In per-row mode, the dot (.) in the template is a single object (the current row).
  The first line of the CSV is assumed to be the header line and will be used as field names,
  except if the --noheader flag is set in which case the fields will be named C1, C2, ...
  The field name specified with --counter will contain the row number (starting at 1).
  If --csv or --template is omitted or empty, stdin is used.
  If --out is omitted or empty, stdout is used in single file mode.     
  If the output file already exists, an error is returned unless --force is set.
  If --csv or --template is not an existing file, it is treated as the actual content.
  The template functions from Sprout are available in the templates.    

Examples:
  csvplate --csv data.csv --template template.txt --out output.txt      
  csvplate -f -i data.csv -t template.txt -o output_{{.Name}}.txt       
  csvplate -i data.csv -d ';' -s 2 -t template.txt
  cat data.csv | csvplate -n -t template.txt

Template data model

  • Each CSV row becomes a map[string]string keyed by column headers (or C1, C2, ... when --noheader is used).
  • The special key defined by --counter provides a 1-based row index as a string.
  • For single-output mode, the template receives a slice of those maps. In per-row mode the template receives the map for the current row.
  • All sprout template functions are available.

Examples

Render a single file containing all rows:

csvplate -i sample.csv -t all_rows.tmpl -o output/all.txt -f

Render one file per CSV row using a dynamic file name:

csvplate -i sample.csv -t per_row.tmpl -o "output/{{ .Name }}.txt" -f

Render a semicolon-delimited CSV by providing an explicit separator and skipping the first line:

csvplate --csv french.csv --csv-sep ';' --skip 1 --template all_rows.tmpl --out output/fr_all.txt --force

You can check the example/ folder to see the provided examples and templates.

Installation

Precompiled executables

You can download the executable for your platform from the releases.

Compile it yourself
go install github.com/kpym/csvplate@latest

License

Released under the MIT License.

Documentation

Overview

csvplate is a small utilisty that takes a csvfile and a golang template and generates one or multimple output files based on the template. If the output file name contains a template expression, it will be evaluated for every row and new files will be created, else a single file will be created. If single file is created the . is a slice of objects, else the . is a single object. The first line is assumed to be the header line and will be used as the field names, except if the -noheader flag is set in which case the fields will be named C1, C2, ... The template functions from Sprout are available in the templates. Usage:

csvplate [-noheader] -csv input.csv -template template.txt -out output.txt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址