3 个版本 (破坏性)
0.3.0 | 2020 年 3 月 2 日 |
---|---|
0.2.0 | 2020 年 3 月 2 日 |
0.1.0 | 2020 年 3 月 1 日 |
#23 in #csv-tsv
13KB
239 代码行
csv-exec 对 CSV 文件的每一行执行命令。命令的参数被 CSV 列的值替换。输出写入新列。
$ cat test.csv
Id,Dir
24,example.com/a
68,example.com/b
$ csv-exec 'echo $2/$1' <test.csv
Id,Dir,Result
24,example.com/a,example.com/a/24
68,example.com/b,example.com/b/68
解析参数的正则表达式可以更改
$ csv-exec 'echo €2/€1' --arg-regex '€([0-9]+)' <test.csv
Id,Dir,Result
24,example.com/a,example.com/a/24
68,example.com/b,example.com/b/68
由 clap 生成的帮助信息
$ csv-exec -h
csv-exec 0.3.0
niladic <[email protected]>
Execute a command on each record of a CSV.
USAGE:
csv-exec [FLAGS] [OPTIONS] <COMMAND>
FLAGS:
-h, --help Prints help information
-n, --no-headers Do not read the first line as a header line
-V, --version Prints version information
OPTIONS:
--arg-regex <REGEX> Regex used to parse the column position in the command args.
Position begins at 1.
Only the first capturing group is used.
Syntax: https://docs.rs/regex/1.3.4/regex/index.html#syntax
[default: \$([0-9]+)]
-d, --delimiter <CHAR> CSV delimiter (\t for tabs) [default: ,]
-i, --input <FILE> Input CSV file [stdin by default]
--new-column-name <STRING> Name of the new column which contains the results [default: Result]
--out-delimiter <CHAR> Output CSV delimiter, if different from delimiter (\t for tabs)
-o, --output <FILE> Output CSV [stdout by default]
--quote <CHAR> CSV quote [default: "]
ARGS:
<COMMAND> The command to execute
依赖项
~4–5.5MB
~82K SLoC