cmd

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const VERSION = "0.30.0"

VERSION of csvtk

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "csvtk",
	Short: "A cross-platform, efficient and practical CSV/TSV toolkit",
	Long: fmt.Sprintf(`csvtk -- a cross-platform, efficient and practical CSV/TSV toolkit

Version: %s

Author: Wei Shen <shenwei356@gmail.com>

Documents  : http://shenwei356.github.io/csvtk
Source code: https://github.com/shenwei356/csvtk

Attention:

  1. By default, csvtk assumes input files have header row, if not, switch flag "-H" on.
  2. By default, csvtk handles CSV files, use flag "-t" for tab-delimited files.
  3. Column names should be unique.
  4. By default, lines starting with "#" will be ignored, if the header row
     starts with "#", please assign flag "-C" another rare symbol, e.g. '$'.
  5. Do not mix use field (column) numbers and names to specify columns to operate.
  6. The CSV parser requires all the lines have same numbers of fields/columns.
     Even lines with spaces will cause error.
     Use '-I/--ignore-illegal-row' to skip these lines if neccessary.
     You can also use "csvtk fix" to fix files with different numbers of columns in rows.
  7. If double-quotes exist in fields not enclosed with double-quotes, e.g.,
         x,a "b" c,1
     It would report error:
         bare " in non-quoted-field.
     Please switch on the flag "-l" or use "csvtk fix-quotes" to fix it.
  8. If somes fields have only a double-quote eighter in the beginning or in the end, e.g.,
         x,d "e","a" b c,1
     It would report error:
         extraneous or missing " in quoted-field
     Please use "csvtk fix-quotes" to fix it, and use "csvtk del-quotes" to reset to the
     original format as needed.

Environment variables for frequently used global flags:

  - "CSVTK_T" for flag "-t/--tabs"
  - "CSVTK_H" for flag "-H/--no-header-row"
  - "CSVTK_QUIET" for flag "--quiet"

You can also create a soft link named "tsvtk" for "csvtk", 
which sets "-t/--tabs" by default.

`, VERSION),
}

RootCmd represents the base command when called without any subcommands

Functions

func ExcelColumnIndex added in v0.23.0

func ExcelColumnIndex(col int) string

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func NewCSVWriterChanByConfig

func NewCSVWriterChanByConfig(config Config) (chan []string, error)

NewCSVWriterChanByConfig returns a chanel which you can send record to write

func ParseByteSize added in v0.26.0

func ParseByteSize(val string) (int64, error)

ParseByteSize parses byte size from string

func UniqInts added in v0.27.0

func UniqInts(list []int) []int

Types

type CSVReader

type CSVReader struct {
	NoHeaderRow   bool
	ShowRowNumber bool

	Reader *csv.Reader

	Ch chan Record

	IgnoreEmptyRow   bool
	IgnoreIllegalRow bool
	NumEmptyRows     []int // rows of emtpy rows
	NumIllegalRows   []int // rows of illegal rows
	// contains filtered or unexported fields
}

CSVReader is

func NewCSVReader

func NewCSVReader(file string) (*CSVReader, error)

NewCSVReader is

func (*CSVReader) Read added in v0.27.0

func (csvReader *CSVReader) Read(opt ReadOption)

Run begins to read

type Config

type Config struct {
	Verbose bool

	NumCPUs int

	Delimiter    rune
	OutDelimiter rune
	// QuoteChar   rune
	CommentChar rune
	LazyQuotes  bool

	Tabs        bool
	OutTabs     bool
	NoHeaderRow bool
	NoOutHeader bool

	ShowRowNumber bool

	OutFile string

	IgnoreEmptyRow   bool
	IgnoreIllegalRow bool
}

Config is the struct containing all global flags

type ReadOption added in v0.27.0

type ReadOption struct {
	FieldStr                       string
	FieldStrSep                    string
	FuzzyFields                    bool
	IgnoreFieldCase                bool
	DoNotAllowDuplicatedColumnName bool
	UniqColumn                     bool // deduplicate columns matched by multiple fuzzy column names
	AllowMissingColumn             bool // allow missing column
	BlankMissingColumn             bool
	ShowRowNumber                  bool

	Verbose bool
}

type Record added in v0.27.0

type Record struct {
	Line int // line number, if the original file contains blank lines, the number would be inaccurate.
	Row  int // the row number, header row skipped
	Err  error

	IsHeaderRow        bool // is current record the header row
	SelectWithColnames bool // wether user use colnames to select fields

	All      []string
	Fields   []int    // selected fields
	Selected []string // selected columns
}

Record is a CSV/TSV record

Jump to

Keyboard shortcuts

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