【问题标题】:How to format csv into multiline newline delimited plain text output using csvkit如何使用 csvkit 将 csv 格式化为多行换行符分隔的纯文本输出
【发布时间】:2018-07-08 14:39:19
【问题描述】:

我有一个这样的 csv,

type,name,ad1,pin,ph
"A","aaaaa","23 rd.","45789","4578954"
"F","bbbbb","23 rd.","84789","4578954"
"D","ccccc","34 rd.","45646","7845663"

这需要被格式化成这样的纯文本文件。

type
name
ad1, PIN-pin
PH: ph

所以最终的输出应该是这样的。

A
aaaaa
23 rd., PIN- 45789,
PH: 4578954

F
bbbbb
23 rd. PIN-84789
PH:4578954

D
ccccc
34 rd., PIN-45646
PH: 7845663

是否有可能在 csvkit 中实现这一点。

【问题讨论】:

标签: csvkit


【解决方案1】:

您可以使用 miller (https://github.com/johnkerl/miller/releases/tag/5.4.0):

mlr --c2x --ops "\t" put '$1=$type;$2=$name;$3=($ad1 . ", PIN-" . $pin);$4=("PH: " . $ph)' \
then cut -r -f "^[0-9]" input.csv | \
cut -f2

拥有

A
aaaaa
23 rd., PIN-45789
PH: 4578954

F
bbbbb
23 rd., PIN-84789
PH: 4578954

D
ccccc
34 rd., PIN-45646
PH: 7845663

一些注意事项:

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 2014-08-14
    • 2020-06-22
    相关资源
    最近更新 更多