Skip to content

Commit 69dbbe9

Browse files
committed
v0.2.3
1 parent ee5e8c6 commit 69dbbe9

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Read Gzip | Yes | Yes |
7171
Fields ranges | Yes | Yes | e.g. `-f 1-4,6`
7272
**Unselect fileds** | Yes | -- | e.g. `-1` for excluding first column
7373
**Fuzzy fields** | Yes | -- | e.g. `ab*` for columns with prefix "ab"
74+
Order-specific fields | -- | Yes | it means `1,2` is different from `2,1`
7475
Rename columns | Yes | -- | rename with new name(s) or from existed names
7576
Sort by multiple keys | Yes | Yes | bash sort like operations
7677
Sort by number | Yes | -- | e.g. `-k 1:n`
@@ -120,7 +121,8 @@ to be continued...
120121

121122
1. Join multiple files by keys (`join`)
122123

123-
- `csvtk join -f "username;username;name" names.csv phone.csv adress.csv -k`
124+
- All files have same key column: `csvtk join -f id file1.csv file2.csv`
125+
- Files have different key columns: `csvtk join -f "username;username;name" names.csv phone.csv adress.csv -k`
124126

125127
## Contact
126128

csvtk/cmd/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ type Config struct {
172172
func getConfigs(cmd *cobra.Command) Config {
173173
return Config{
174174
ChunkSize: getFlagPositiveInt(cmd, "chunk-size"),
175-
NumCPUs: getFlagPositiveInt(cmd, "num-cups"),
175+
NumCPUs: getFlagPositiveInt(cmd, "num-cpus"),
176176

177177
Delimiter: getFlagRune(cmd, "delimiter"),
178178
OutDelimiter: getFlagRune(cmd, "out-delimiter"),

csvtk/cmd/join.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ import (
3434
var joinCmd = &cobra.Command{
3535
Use: "join",
3636
Short: "join multiple CSV files by selected fields",
37-
Long: ` join multiple CSV files by selected fields.
38-
Join 2- files to the first one.
37+
Long: ` join 2nd and later files to the first file by selected fields.
38+
39+
Multiple keys supported, but the orders are ignored.
3940
4041
`,
4142
Run: func(cmd *cobra.Command, args []string) {
@@ -48,7 +49,13 @@ Join 2- files to the first one.
4849
}
4950

5051
allFields := getFlagSemicolonSeparatedStrings(cmd, "fields")
51-
if len(allFields) != len(files) {
52+
if len(allFields) == 1 {
53+
s := make([]string, len(files))
54+
for i := range files {
55+
s[i] = allFields[0]
56+
}
57+
allFields = s
58+
} else if len(allFields) != len(files) {
5259
checkError(fmt.Errorf("number of fields (%d) should be equal to number of files (%d)", len(allFields), len(files)))
5360
}
5461
// ignoreCase := getFlagBool(cmd, "ignore-case")
@@ -153,7 +160,8 @@ Join 2- files to the first one.
153160

154161
func init() {
155162
RootCmd.AddCommand(joinCmd)
156-
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`)
163+
joinCmd.Flags().StringP("fields", "f", "1", "Semicolon seperated key fields of all files, "+
164+
"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")
157165
joinCmd.Flags().BoolP("ignore-case", "i", false, `ignore case`)
158166
joinCmd.Flags().BoolP("fuzzy-fields", "F", false, `using fuzzy fileds, e.g. *name or id123*`)
159167
joinCmd.Flags().BoolP("keep-unmatched", "k", false, `keep unmatched data of the first file`)

csvtk/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func Execute() {
5555

5656
func init() {
5757
RootCmd.PersistentFlags().IntP("chunk-size", "c", 50, `chunk size of CSV reader`)
58-
RootCmd.PersistentFlags().IntP("num-cups", "j", runtime.NumCPU(), `number of CPUs to use (default value depends on your computer)`)
58+
RootCmd.PersistentFlags().IntP("num-cpus", "j", runtime.NumCPU(), `number of CPUs to use (default value depends on your computer)`)
5959

6060
RootCmd.PersistentFlags().StringP("delimiter", "d", ",", `delimiting character of the input CSV file`)
6161
RootCmd.PersistentFlags().StringP("out-delimiter", "D", ",", `delimiting character of the input CSV file`)

doc/docs/download.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- [csvtk v0.2.3](https://github.com/shenwei356/csvtk/releases/tag/v0.2.3)
1010
- add flag `--colnames` to `cut`
11+
- flag `-f` (`--fields`) of `join` supports single value now
1112

1213
## Installation
1314

@@ -38,7 +39,7 @@ You can also add the directory of the executable file to environment variable
3839
- [csvtk v0.2.1](https://github.com/shenwei356/csvtk/releases/tag/v0.2.1)
3940
- fix bug of `mutate`
4041

41-
42+
4243
<div id="disqus_thread"></div>
4344
<script>
4445
/**

doc/docs/usage.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Usage
77
```
88
Another cross-platform, efficient and practical CSV/TSV toolkit
99
10-
Version: 0.2.2
10+
Version: 0.2.3
1111
1212
Author: Wei Shen <[email protected]>
1313
@@ -72,7 +72,7 @@ Examples
7272
7 8 0
7373
8 1,000 4
7474

75-
$ csvtk transpose -t digitals.tsv
75+
$ csvtk transpose -t digitals.tsv
7676
4 1 7 8
7777
5 2 8 1,000
7878
6 3 0 4
@@ -169,24 +169,25 @@ Examples
169169
Usage
170170

171171
```
172-
join multiple CSV files by selected fields.
173-
Join 2- files to the first one.
172+
join 2nd and later files to the first file by selected fields.
173+
174+
Multiple keys supported, but the orders are ignored.
174175
175176
Usage:
176177
csvtk join [flags]
177178
178179
Flags:
179-
-f, --fields string Semicolon seperated key fields of all files. e.g -f 1,2;2,3 or -f A,B;C,D
180+
-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")
180181
-F, --fuzzy-fields using fuzzy fileds, e.g. *name or id123*
181182
-i, --ignore-case ignore case
182183
-k, --keep-unmatched keep unmatched data of the first file
183184
184-
185185
```
186186

187187
Examples:
188188

189-
- `csvtk join -f "username;username;name" names.csv phone.csv adress.csv -k`
189+
- All files have same key column: `csvtk join -f id file1.csv file2.csv`
190+
- Files have different key columns: `csvtk join -f "username;username;name" names.csv phone.csv adress.csv -k`
190191

191192
## rename
192193

@@ -303,7 +304,7 @@ Examples
303304
- Complex sort: `csvtk sort -k region -k age:n -k id:nr`
304305

305306

306-
307+
307308
<div id="disqus_thread"></div>
308309
<script>
309310
/**

doc/site

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit c80de9f720f906da64dc692abde6020059bbb7fb
1+
Subproject commit aa97e1bbdf30b16dd64c7cbdbd4895e3d11dc681

0 commit comments

Comments
 (0)