Skip to content

Commit

Permalink
v0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Apr 10, 2016
1 parent ee5e8c6 commit 69dbbe9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion csvtk/cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
16 changes: 12 additions & 4 deletions csvtk/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
Expand Down Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion csvtk/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
3 changes: 2 additions & 1 deletion doc/docs/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`


<div id="disqus_thread"></div>
<script>
/**
Expand Down
17 changes: 9 additions & 8 deletions doc/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage
```
Another cross-platform, efficient and practical CSV/TSV toolkit
Version: 0.2.2
Version: 0.2.3
Author: Wei Shen <[email protected]>
Expand Down Expand Up @@ -72,7 +72,7 @@ Examples
7 8 0
8 1,000 4

$ csvtk transpose -t digitals.tsv
$ csvtk transpose -t digitals.tsv
4 1 7 8
5 2 8 1,000
6 3 0 4
Expand Down Expand Up @@ -169,24 +169,25 @@ Examples
Usage

```
join multiple CSV files by selected fields.
Join 2- files to the first one.
join 2nd and later files to the first file by selected fields.
Multiple keys supported, but the orders are ignored.
Usage:
csvtk join [flags]
Flags:
-f, --fields string Semicolon seperated key fields of all files. e.g -f 1,2;2,3 or -f A,B;C,D
-f, --fields string 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 (default "1")
-F, --fuzzy-fields using fuzzy fileds, e.g. *name or id123*
-i, --ignore-case ignore case
-k, --keep-unmatched keep unmatched data of the first file
```

Examples:

- `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`

## rename

Expand Down Expand Up @@ -303,7 +304,7 @@ Examples
- Complex sort: `csvtk sort -k region -k age:n -k id:nr`



<div id="disqus_thread"></div>
<script>
/**
Expand Down
2 changes: 1 addition & 1 deletion doc/site
Submodule site updated from c80de9 to aa97e1

0 comments on commit 69dbbe9

Please sign in to comment.