csvutil

package module
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2017 License: MIT Imports: 23 Imported by: 0

README

csvutil

Build Status Coverage Status Go Report Card Godoc license

Description

CSVに対して様々な処理を行うコマンドラインツールです。
CSVの構成操作、およびダミーデータ生成が可能です。
それぞれのサブコマンドはパイプで組み合わせて利用できます。

Usage

ダミーデータ生成サンプル:

$ csvutil generate --size 5 --count 10 --header 氏名:郵便番号:住所:建物:メール | \
  csvutil name --name 氏名 | \
  csvutil address --zip-code 郵便番号 --prefecture 住所 --city 住所 --town 住所 --block-number | \
  csvutil building --column 建物 | \
  csvutil email --column メール

出力結果:

氏名,郵便番号,住所,建物,メール
土田 慶太郎,061-8035,京都府和光市西春別駅前西町42-18,プレステージ前河原1926,tempora_doloribus_inventore@twitterbeat.info
古川 篤人,468-2410,長崎県東根市御蔵島村一円16,テラスライフ1421,charlesstevens@eire.mil
横田 姫葵,197-3356,愛知県志木市神田佐久間河岸44-12-6,ソレイユ麻生1229,qjordan@roomm.edu
荻野 吉文,819-3023,東京都大阪市平野区亀尾町44-24-2,グリーンエステート1727,tempore_numquam_consequatur@midel.org
森山 沙江,289-9318,岡山県大阪市東淀川区桜作42-6,グレースヴィレッジ宇和町杢所1118,ucooper@voonder.net
大野 沙祈,093-0401,新潟県河北郡内灘町木興町46-10,パールレジデンス梨ケ原806,victorpierce@dynabox.edu
山崎 玲菜,065-9621,兵庫県大阪市浪速区八幡町39-18,スイートコート光町506,qui_aut_nihil@meeveo.biz
金沢 優二,201-6394,徳島県岩手郡雫石町日置野田36-10,プレステージ八森樋長421,ibell@demizz.com
松原 誠吾,877-1329,石川県吉野郡野迫川村灘38-5-10,ガーデンタワー藤河内1120,ab_cum@voomm.info
坂井 力也,967-7366,愛媛県大阪市西区白鳥町中津屋41,レイクパーク609,perferendis_earum@quamba.edu

csvutil help で全体のヘルプを確認し、csvutil help [subcommand] で各サブコマンドの詳細なヘルプを確認してください。

Install

Releases · pinzolo/csvutil から最新の自分の環境にあったバイナリをダウンロードしてお使いください。

また、Go環境がある場合 go get でインストールできます。(Go 1.8以上)

$ go get github.com/pinzolo/csvutil/cmd/csvutil

Contribution

  1. Fork (https://github.com/pinzolo/csvutil/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create a new Pull Request

Author

pinzolo

Documentation

Index

Constants

View Source
const (
	// SortDataTypeText is used when want use value as text.
	SortDataTypeText = "text"
	// SortDataTypeNumber is used when want use value as number.
	SortDataTypeNumber = "number"
	// EmptyNatural is used when empty string is ordered in natural.
	EmptyNatural = "natural"
	// EmptyFirst is used when empty string is ordered in first.
	EmptyFirst = "first"
	// EmptyLast is used when empty string is ordered in last.
	EmptyLast = "last"
)

Variables

View Source
var Version = semver.Version{
	Major: 0,
	Minor: 24,
	Patch: 0,
}

Version of csvutil.

Functions

func Address

func Address(r io.Reader, w io.Writer, o AddressOption) error

Address overwrite value of given column by dummy address.

func Append

func Append(r io.Reader, w io.Writer, o AppendOption) error

Append empty values to end of each lines.

func Blank

func Blank(r io.Reader, w io.Writer, o BlankOption) error

Blank overwrite value of given column by empty or spaces.

func Building

func Building(r io.Reader, w io.Writer, o BuildingOption) error

Building overwrite value of given column by dummy office or apartment.

func Collect added in v0.19.0

func Collect(r io.Reader, w io.Writer, o CollectOption) error

Collect print collected CSV values.

func Combine added in v0.15.1

func Combine(r io.Reader, w io.Writer, o CombineOption) error

Combine column(s) from CSV.

func Convert added in v0.21.0

func Convert(r io.Reader, w io.Writer, o ConvertOption) error

Convert CSV.

func Count

func Count(r io.Reader, o CountOption) (int, error)

Count CSV lines.

func Email

func Email(r io.Reader, w io.Writer, o EmailOption) error

Email overwrite value of given column by dummy email address.

func Extract

func Extract(r io.Reader, w io.Writer, o ExtractOption) error

Extract column(s) from CSV.

func Filter added in v0.22.0

func Filter(r io.Reader, w io.Writer, o FilterOption) error

Filter value of given column.

func Generate

func Generate(w io.Writer, o GenerateOption) error

Generate empty values CSV.

func Header(r io.Reader, w io.Writer, o HeaderOption) error

Header print headers of CSV.

func Insert

func Insert(r io.Reader, w io.Writer, o InsertOption) error

Insert empty values to CSV

func Name

func Name(r io.Reader, w io.Writer, o NameOption) error

Name overwrite value of given column by dummy name.

func NewReader

func NewReader(r io.Reader) (*csv.Reader, bool)

NewReader returns *csv.Reader for UTF8. If source has BOM, returns true as second return value.

func NewReaderWithEnc

func NewReaderWithEnc(r io.Reader, e encoding.Encoding) *csv.Reader

NewReaderWithEnc returns *csv.Reader for given encoding.

func NewWriter

func NewWriter(w io.Writer, bom bool) *csv.Writer

NewWriter returns *csv.Writer for UTF8. If true is given as bom, Writer writes BOM at the top.

func NewWriterWithEnc

func NewWriterWithEnc(w io.Writer, e encoding.Encoding) *csv.Writer

NewWriterWithEnc returns *csv.Writer for given encoding.

func Numeric added in v0.24.0

func Numeric(r io.Reader, w io.Writer, o NumericOption) error

Numeric overwrite value of given column by random numbers.

func Password added in v0.20.0

func Password(r io.Reader, w io.Writer, o PasswordOption) error

Password overwrite value of given column by dummy password address.

func Remove

func Remove(r io.Reader, w io.Writer, o RemoveOption) error

Remove column(s) in CSV.

func Size

func Size(r io.Reader, o SizeOption) (int, error)

Size CSV lines.

func Sort added in v0.24.0

func Sort(r io.Reader, w io.Writer, o SortOption) error

Sort CSV.

func Substitute added in v0.16.0

func Substitute(r io.Reader, w io.Writer, o SubstituteOption) error

Substitute value of given column.

func Tail added in v0.18.0

func Tail(r io.Reader, w io.Writer, o TailOption) error

Tail reads lines from tail.

func Tel

func Tel(r io.Reader, w io.Writer, o TelOption) error

Tel overwrite value of given column by dummy tel number.

func Top added in v0.18.0

func Top(r io.Reader, w io.Writer, o TopOption) error

Top reads lines from top.

func UTF8BOM

func UTF8BOM() []byte

UTF8BOM is bytes for byte order mark of UTF8.

Types

type AddressOption

type AddressOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// ZipCode column symbol.
	ZipCode string
	// Prefecture column symbol.
	Prefecture string
	// Output prefecture code.
	PrefectureCode bool
	// City column symbol.
	City string
	// Town column symbol.
	Town string
	// BlockNumber output flag.
	BlockNumber bool
	// BlockNumber width(1 or 2)
	NumberWidth int
}

AddressOption is option holder for Address.

type AppendOption

type AppendOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Headers is appending header list.
	Headers []string
	// Size is appending column size.
	Size int
}

AppendOption is option holder for Append.

type BlankOption

type BlankOption struct {
	// Source file does not have hdr line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// ColumnSyms hdr or column index list.
	ColumnSyms []string
	// Rate of fill
	Rate int
	// Space character width.
	//   0: no space(empaty)
	//   1: half space
	//   2: full width space
	SpaceWidth int
	// Space character count.
	SpaceSize int
}

BlankOption is option holder for Blank.

type BuildingOption

type BuildingOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output
	OutputEncoding string
	// Target column symbol
	Column string
	// Rate of office output
	OfficeRate int
	// BlockNumber width(1 or 2)
	NumberWidth int
	// Append to source value
	Append bool
}

BuildingOption is option holder for Building.

type CSVProcessor added in v0.15.1

type CSVProcessor struct {
	// contains filtered or unexported fields
}

CSVProcessor process CSV read from csv.Reader, and write to csv.Writer.

func NewCSVProcessor added in v0.15.1

func NewCSVProcessor(r *csv.Reader, w *csv.Writer) *CSVProcessor

NewCSVProcessor returns new processor from reader and writer.

func NewReadOnlyCSVProcessor added in v0.19.0

func NewReadOnlyCSVProcessor(r *csv.Reader) *CSVProcessor

NewReadOnlyCSVProcessor returns new processor from reader. Processor does not write to CSV.

func (*CSVProcessor) Process added in v0.15.1

func (csvp *CSVProcessor) Process() error

Process CSV. Read each line and apply each functions and write line.

func (*CSVProcessor) SetHeaderHanlder added in v0.15.1

func (csvp *CSVProcessor) SetHeaderHanlder(f func([]string) ([]string, error))

SetHeaderHanlder set function for calling on header line read.

func (*CSVProcessor) SetPreBodyRead added in v0.15.1

func (csvp *CSVProcessor) SetPreBodyRead(f func() error)

SetPreBodyRead set function for calling before first body line read.

func (*CSVProcessor) SetRecordHandler added in v0.15.1

func (csvp *CSVProcessor) SetRecordHandler(f func([]string) ([]string, error))

SetRecordHandler set function for calling on each body line read.

type CollectOption added in v0.19.0

type CollectOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Column symbol of target column
	Column string
	// AllowEmpty as value
	AllowEmpty bool
	// Print count
	PrintCount bool
	// Sort flag
	Sort bool
	// Sort key (value or count)
	SortKey string
	// Sort in descending order
	Descending bool
}

CollectOption is option holder for Collect.

type CombineOption added in v0.15.1

type CombineOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// SourceSyms header or column index list
	SourceSyms []string
	// Destination column symbol
	Destination string
	// Delimiter
	Delimiter string
}

CombineOption is option holder for Combine.

type ConvertOption added in v0.21.0

type ConvertOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Format of converter
	Format string
	// Template for convert
	Template string
	// HTML custom template is given
	HTML bool
}

ConvertOption is option holder for Convert.

type CountOption

type CountOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
}

CountOption is option holder for Count.

type EmailOption

type EmailOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Target column symbol.
	Column string
	// Rate of output mobile email address.
	MobileRate int
}

EmailOption is option holder for Email.

type ExtractOption

type ExtractOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// ColumnSyms header or column index list.
	ColumnSyms []string
}

ExtractOption is option holder for Extract.

type FilterOption added in v0.22.0

type FilterOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output
	OutputEncoding string
	// ColumnSyms header or column index list.
	ColumnSyms []string
	// Target pattern
	Pattern string
	// Use regexp
	Regexp bool
	// contains filtered or unexported fields
}

FilterOption is option holder for Filter.

type GenerateOption

type GenerateOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding for output.
	OutputEncoding string
	// Headers is appending header list.
	Headers []string
	// Size is generating column size.
	Size int
	// Count is generating line count.
	Count int
}

GenerateOption is option holder for Generate.

type HeaderOption

type HeaderOption struct {
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Print index
	Index bool
	// Index origin number
	IndexOrigin int
}

HeaderOption is option holder for Header.

type InsertOption

type InsertOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Headers is header list for insert.
	Headers []string
	// Size is appending column size.
	Size int
	// Before is insert start column symbol.
	Before string
}

InsertOption is option holder for Insert.

type NameOption

type NameOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output
	OutputEncoding string
	// ZipCode column symbol
	ZipCode string
	// Full name column symbol
	Name string
	// First name column symbol
	FirstName string
	// Last name column symbol
	LastName string
	// Kana of full name column symbol
	Kana string
	// Kana of first name column symbol
	FirstKana string
	// Kana of last name column symbol
	LastKana string
	// Output hiragana as kana
	Hiragana bool
	// Gender column symbol
	Gender string
	// Gender format
	GenderFormat string
	// Rate of male output
	MaleRate int
	// Reference column symbol
	Reference string
	// Ignore reference error
	RistrictReference bool
	// Delimiter space width
	SpaceWidth int
}

NameOption is option holder for Name.

type NumericOption added in v0.24.0

type NumericOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Target column symbol.
	Column string
	// Max value
	Max int
	// Min value
	Min int
	// Output decimal instead of integer
	Decimal bool
	// Digit of decimal
	DecimalDigit int
}

NumericOption is option holder for Numeric.

type PasswordOption added in v0.20.0

type PasswordOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Target column symbol.
	Column string
	// MinLength of password
	MinLength int
	// MaxLength of password
	MaxLength int
	// NoNumeric not using number flag
	NoNumeric bool
	// NoUpeer not using upper alphabets flag
	NoUpper bool
	// NoSpecial not using marks flag
	NoSpecial bool
}

PasswordOption is option holder for Password.

type RemoveOption

type RemoveOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// ColumnSyms header or column index list.
	ColumnSyms []string
}

RemoveOption is option holder for Remove.

type SizeOption

type SizeOption struct {
	// Encoding of source file. (default utf8)
	Encoding string
}

SizeOption is option holder for Size.

type SortOption added in v0.24.0

type SortOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Column symbol of target column
	Column string
	// DataType is sort key's data type
	DataType string
	// Sort in descending order
	Descending bool
	// Handling method of empty string
	EmptyHandling string
}

SortOption is option holder for Sort.

type SubstituteOption added in v0.16.0

type SubstituteOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output
	OutputEncoding string
	// Target column symbol
	Column string
	// Target pattern
	Pattern string
	// Replacement value
	Replacement string
	// Use regexp
	Regexp bool
	// contains filtered or unexported fields
}

SubstituteOption is option holder for Substitute.

type TailOption added in v0.18.0

type TailOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Count is reading line count.
	Count int
}

TailOption is option holder for Tail.

type TelOption

type TelOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Target column symbol.
	Column string
	// Rate of output mobile tel number.
	MobileRate int
}

TelOption is option holder for Tel.

type TopOption added in v0.18.0

type TopOption struct {
	// Source file does not have header line. (default false)
	NoHeader bool
	// Encoding of source file. (default utf8)
	Encoding string
	// Encoding for output.
	OutputEncoding string
	// Headers is appending header list.
	Headers []string
	// Count is reading line count.
	Count int
}

TopOption is option holder for Top.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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