Install csv_utility via cargo with the following command
cargo install csv_utilityor build it yourself by pulling the repo.
Name
csv_utility
Author:
Matthias Lodner <[email protected]>
Description:
csv_utility command [flags]
Flags:
-s, --source <string> : path to source file
-d, --destination <string> : path to destination file
-o, --output <string> : path to output file
-m, --mappings <string> : path to mappings file
-t, --threshold <string> : threshold, a positiv number
-h, --help : Show help
Commands:
m, map : Maps entries from source file to header from header file and saves to output file
rer, rmer : Removes empty rows from source csv file and saves to output file
rrwt, rmwt : Remove rows with less than --threshold entries from source csv file and saves to output file
a, append : Appends two csv files with the same header line
s, stats : Shows some stats about the content of the csv file
Version:
0.1.0In the following examples, the table below is used as the source.csv file.
| city | size | population |
|---|---|---|
| New York City | 783,8 | 8,399 |
| Washington, D.C. | 177 | 705.749 |
| Texas | 29.000.000 | |
| California | 423.970 | 39,51 |
| Los Angeles | 1.290,6 | 3.979.576 |
| San Francisco | ||
In this example the content of source.csv gets mapped to the following header from dest.csv and saved to out.csv.
| stadt | einwohner | fläche |
|---|
csv_utility map -s source.csv -d dest.csv -o out.csvRunning the command above opens a user interface with the following options:
Map
Let you map the columns from the source file to the destination file.Save mapping file
Saves the mapping created inMap.Save as new mapping file
Saves the mapping created inMapto a new mapping file.Cancel
Cancels the command.Save and exit
Saves the columns according to the mapping in the output file and exit afterwards.
The result looks like
| stadt | einwohner | fläche |
|---|---|---|
| New York City | 8,399 | 783,8 |
| Washington, D.C. | 705.749 | 177 |
| Texas | 29.000.000 | |
| California | 39,51 | 423.970 |
| Los Angeles | 3.979.576 | 1.290,6 |
| San Francisco | ||
Running the following command on source.csv
csv_utility rmer -s source.csv -o out.csvGets us out.csv with the following content:
| city | size | population |
|---|---|---|
| New York City | 783,8 | 8,399 |
| Washington, D.C. | 177 | 705.749 |
| Texas | 29.000.000 | |
| California | 423.970 | 39,51 |
| Los Angeles | 1.290,6 | 3.979.576 |
| San Francisco |
Running the following command on source.csv
csv_utility rmwt -s source.csv -o out.csv -t 1Gets us out.csv with the following content:
| city | size | population |
|---|---|---|
| New York City | 783,8 | 8,399 |
| Washington, D.C. | 177 | 705.749 |
| Texas | 29.000.000 | |
| California | 423.970 | 39,51 |
| Los Angeles | 1.290,6 | 3.979.576 |
Using the 2 for -t the output file would look like this.
| city | size | population |
|---|---|---|
| New York City | 783,8 | 8,399 |
| Washington, D.C. | 177 | 705.749 |
| California | 423.970 | 39,51 |
| Los Angeles | 1.290,6 | 3.979.576 |
With append the -d file get appended to the -s file and written to the output file.
csv_utility append -s source.csv -d source.csv -o out.csv| city | size | population |
|---|---|---|
| New York City | 783,8 | 8,399 |
| Washington, D.C. | 177 | 705.749 |
| Texas | 29.000.000 | |
| California | 423.970 | 39,51 |
| Los Angeles | 1.290,6 | 3.979.576 |
| San Francisco | ||
| New York City | 783,8 | 8,399 |
| Washington, D.C. | 177 | 705.749 |
| Texas | 29.000.000 | |
| California | 423.970 | 39,51 |
| Los Angeles | 1.290,6 | 3.979.576 |
| San Francisco | ||
The Stats command shows some information about the content of the csv file.
csv_utility append -s source.csv -d source.csv -o out.csv
Stats for in.csv
- 3 columns
- 9 lines total
- 4 full lines
- 2 partly full lines
- 3 empty lines