csvutil

package
v0.39.7 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: MIT Imports: 11 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterCSVFile

func FilterCSVFile(inPath, outPath string, inComma rune, 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 MergeFilterCSVFilesToJSONL

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

func NewReader

func NewReader(rs io.ReadSeeker, comma rune) (*csv.Reader, error)

func NewReaderFile

func NewReaderFile(path string, comma rune) (*csv.Reader, *os.File, error)

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

func NewWriterFile

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

func ParseOneColListToGrid

func ParseOneColListToGrid(lines []string, colCount int, validateLength bool) ([][]string, error)

ParseOneColListToGrid parses a set of lines with one value per row.

func ReadCSVFileSingleColumnValuesString

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

func ReadCSVFilesSingleColumnValuesString

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

func ReadFileOneColListToGrid

func ReadFileOneColListToGrid(filename string, colCount int, validateLength bool) ([][]string, error)

ReadFileOneColListToGrid parses a file with one value per row.

func TrimUTF8ByteOrderMarkString added in v0.37.1

func TrimUTF8ByteOrderMarkString(s string) string

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.

func WriteFile

func WriteFile(filename string, rows [][]string) error

WriteFile writes a `[][]string` to a file.

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