Skip to content
Format delimited data into columns
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
golumn.go
golumn_test.go
line.go
parser.go

README.md

golumn

Format delimited data into columns. Similar to the unix shell program column.

Example

Some CSV file:

Date,Type,Description,Amount
30/10/2013,DEB,SUPERMARKET 29833,5.15
29/10/2013,DEB,AMAZON MKPLACE,5.63

Parse the file:

var result = golumn.parse(string(data), ",", golumn.Options{
	MaxColumnWidth: 5,
	Truncate:       true,
})
print(result)

Prints the following:

Date 	Type	Descr	Amoun
 30/1	DEB 	SUPER	5.15 
 29/1	DEB 	AMAZO	5.63 

Usage

Download and compile the source with go get github.com/st3redstripe/golumn. Then import as usual.

import (
	"github.com/st3redstripe/golumn"
)

Call Parse passing in an input string and a delimiter.

func Parse(input string, delim string) string

Use ParseF to override default options.

func ParseF(input string, delim string, options Options) string

Options

For use with ParseF - where options is a golumn.Options struct containing a subset of the following

  • ColumnSpacer string - The characters used to pad columns, default is \t.
  • NewLine string - New line character, default is \n.
  • ColumnWidth int - Sets colums to be a fixed width.
  • MaxColumnWidth int - Constrains column widths. Overidden if a valid ColumnWidth option is given.
  • Truncate bool - Truncates any cells that overflow the ColumnWidth or MaxColumnWidth.
You can’t perform that action at this time.