csvutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugReadCSV = false // should not need to edit

Functions

func FilterCSVFile

func FilterCSVFile(inPath, outPath string, inComma rune, inStripBom bool, andFilter map[string]stringsutil.MatchInfo) error

func MergeFilterCSVFiles

func MergeFilterCSVFiles(inPaths []string, outPath string, inComma rune, inStripBom bool, andFilter map[string]stringsutil.MatchInfo) error

MergeFilterCSVFiles can merge and filter multiple CSV files. It expects row definitions to be the same across all input files.

func MergeFilterCSVFilesToJSON

func MergeFilterCSVFilesToJSON(inPaths []string, outPath string, inComma rune, inStripBom bool, perm os.FileMode, andFilter map[string]stringsutil.MatchInfo) error

func MergeFilterCSVFilesToJSONL

func MergeFilterCSVFilesToJSONL(inPaths []string, outPath string, inComma rune, inStripBom bool, andFilter map[string]stringsutil.MatchInfo) error

func NewReader

func NewReader(path string, comma rune, stripBom bool) (*csv.Reader, *os.File, error)

NewReader will create a csv.Reader and optionally strip off the byte order mark (BOM) if requested. Close file reader with `defer f.Close()`.

func NewTableDataFileCSV

func NewTableDataFileCSV(path string, comma rune, stripBom bool) (table.TableData, error)

NewTableDataFileCSV reads in a CSV file and returns a TableData struct.

func NewTableDataFileSimple

func NewTableDataFileSimple(path string, sep string, hasHeader, trimSpace bool) (table.TableData, error)

func NewTableDataFilesSimple

func NewTableDataFilesSimple(filenames []string, sep string, hasHeader, trimSpace bool) (table.TableData, error)

func NewWriterFile

func NewWriterFile(filename string) (*csv.Writer, *os.File, error)

func ReadCSVFileSingleColumnValuesString

func ReadCSVFileSingleColumnValuesString(filename, sep string, hasHeader, trimSpace bool, col uint, condenseUniqueSort bool) ([]string, error)

func ReadCSVFilesSingleColumnValuesString

func ReadCSVFilesSingleColumnValuesString(files []string, sep string, hasHeader, trimSpace bool, col uint, condenseUniqueSort bool) ([]string, error)

func ReadMergeFilterCSVFiles

func ReadMergeFilterCSVFiles(inPaths []string, outPath string, inComma rune, inStripBom bool, andFilter map[string]stringsutil.MatchInfo) (table.DocumentsSet, error)

func WriteCSVFiltered

func WriteCSVFiltered(reader *csv.Reader, writer *csv.Writer, andFilter map[string]stringsutil.MatchInfo, writeHeader bool) error

WriteCSVFiltered filters an existing CSV and writes the matching lines to a *csv.Writer.

Types

type CSVHeader

type CSVHeader struct {
	Columns []string
}

func (*CSVHeader) Index

func (ch *CSVHeader) Index(want string) int

func (*CSVHeader) RecordMatch

func (ch *CSVHeader) RecordMatch(row []string, andFilter map[string]stringsutil.MatchInfo) (bool, error)

func (*CSVHeader) RecordToMSS

func (ch *CSVHeader) RecordToMSS(row []string) map[string]string

type Writer

type Writer struct {
	Separator        string
	StripRepeatedSep bool
	ReplaceSeparator bool
	SeparatorAlt     string
	File             *os.File
}

Writer is a struct for a CSV/TSV writer.

func NewWriter

func NewWriter(filepath, sep string, replaceSeparator bool, alt string) (Writer, error)

NewWriter returns a Writer with the separator params set.

func (*Writer) AddLine

func (w *Writer) AddLine(cells []interface{}) error

AddLine adds an []interface{} to the file.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the file.

Jump to

Keyboard shortcuts

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