From 69dbbe9aa5832ea2b3171c92265f2f5fc21fc156 Mon Sep 17 00:00:00 2001 From: shenwei356 Date: Sun, 10 Apr 2016 20:05:50 +0800 Subject: [PATCH] v0.2.3 --- README.md | 4 +++- csvtk/cmd/helper.go | 2 +- csvtk/cmd/join.go | 16 ++++++++++++---- csvtk/cmd/root.go | 2 +- doc/docs/download.md | 3 ++- doc/docs/usage.md | 17 +++++++++-------- doc/site | 2 +- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c9c1631..f46f5d0 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Read Gzip | Yes | Yes | Fields ranges | Yes | Yes | e.g. `-f 1-4,6` **Unselect fileds** | Yes | -- | e.g. `-1` for excluding first column **Fuzzy fields** | Yes | -- | e.g. `ab*` for columns with prefix "ab" +Order-specific fields | -- | Yes | it means `1,2` is different from `2,1` Rename columns | Yes | -- | rename with new name(s) or from existed names Sort by multiple keys | Yes | Yes | bash sort like operations Sort by number | Yes | -- | e.g. `-k 1:n` @@ -120,7 +121,8 @@ to be continued... 1. Join multiple files by keys (`join`) - - `csvtk join -f "username;username;name" names.csv phone.csv adress.csv -k` + - All files have same key column: `csvtk join -f id file1.csv file2.csv` + - Files have different key columns: `csvtk join -f "username;username;name" names.csv phone.csv adress.csv -k` ## Contact diff --git a/csvtk/cmd/helper.go b/csvtk/cmd/helper.go index 1784026..09c3682 100644 --- a/csvtk/cmd/helper.go +++ b/csvtk/cmd/helper.go @@ -172,7 +172,7 @@ type Config struct { func getConfigs(cmd *cobra.Command) Config { return Config{ ChunkSize: getFlagPositiveInt(cmd, "chunk-size"), - NumCPUs: getFlagPositiveInt(cmd, "num-cups"), + NumCPUs: getFlagPositiveInt(cmd, "num-cpus"), Delimiter: getFlagRune(cmd, "delimiter"), OutDelimiter: getFlagRune(cmd, "out-delimiter"), diff --git a/csvtk/cmd/join.go b/csvtk/cmd/join.go index 117dd9c..043d006 100644 --- a/csvtk/cmd/join.go +++ b/csvtk/cmd/join.go @@ -34,8 +34,9 @@ import ( var joinCmd = &cobra.Command{ Use: "join", Short: "join multiple CSV files by selected fields", - Long: ` join multiple CSV files by selected fields. -Join 2- files to the first one. + Long: ` join 2nd and later files to the first file by selected fields. + +Multiple keys supported, but the orders are ignored. `, Run: func(cmd *cobra.Command, args []string) { @@ -48,7 +49,13 @@ Join 2- files to the first one. } allFields := getFlagSemicolonSeparatedStrings(cmd, "fields") - if len(allFields) != len(files) { + if len(allFields) == 1 { + s := make([]string, len(files)) + for i := range files { + s[i] = allFields[0] + } + allFields = s + } else if len(allFields) != len(files) { checkError(fmt.Errorf("number of fields (%d) should be equal to number of files (%d)", len(allFields), len(files))) } // ignoreCase := getFlagBool(cmd, "ignore-case") @@ -153,7 +160,8 @@ Join 2- files to the first one. func init() { RootCmd.AddCommand(joinCmd) - joinCmd.Flags().StringP("fields", "f", "", `Semicolon seperated key fields of all files. e.g -f 1,2;2,3 or -f A,B;C,D`) + joinCmd.Flags().StringP("fields", "f", "1", "Semicolon seperated key fields of all files, "+ + "if given one, we think all the files have the same key columns. e.g -f 1;2 or -f A,B;C,D or -f id") joinCmd.Flags().BoolP("ignore-case", "i", false, `ignore case`) joinCmd.Flags().BoolP("fuzzy-fields", "F", false, `using fuzzy fileds, e.g. *name or id123*`) joinCmd.Flags().BoolP("keep-unmatched", "k", false, `keep unmatched data of the first file`) diff --git a/csvtk/cmd/root.go b/csvtk/cmd/root.go index 2071345..13ca861 100644 --- a/csvtk/cmd/root.go +++ b/csvtk/cmd/root.go @@ -55,7 +55,7 @@ func Execute() { func init() { RootCmd.PersistentFlags().IntP("chunk-size", "c", 50, `chunk size of CSV reader`) - RootCmd.PersistentFlags().IntP("num-cups", "j", runtime.NumCPU(), `number of CPUs to use (default value depends on your computer)`) + RootCmd.PersistentFlags().IntP("num-cpus", "j", runtime.NumCPU(), `number of CPUs to use (default value depends on your computer)`) RootCmd.PersistentFlags().StringP("delimiter", "d", ",", `delimiting character of the input CSV file`) RootCmd.PersistentFlags().StringP("out-delimiter", "D", ",", `delimiting character of the input CSV file`) diff --git a/doc/docs/download.md b/doc/docs/download.md index d4295a3..663c2bc 100644 --- a/doc/docs/download.md +++ b/doc/docs/download.md @@ -8,6 +8,7 @@ - [csvtk v0.2.3](https://github.com/shenwei356/csvtk/releases/tag/v0.2.3) - add flag `--colnames` to `cut` + - flag `-f` (`--fields`) of `join` supports single value now ## Installation @@ -38,7 +39,7 @@ You can also add the directory of the executable file to environment variable - [csvtk v0.2.1](https://github.com/shenwei356/csvtk/releases/tag/v0.2.1) - fix bug of `mutate` - +