csvkit

How to format csv into multiline newline delimited plain text output using csvkit


I have a csv like this,

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

this needs to be formatted to a plain text file like this.

type
name
ad1, PIN-pin
PH: ph

So the final output would be like this.

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

F
bbbbb
23 rd. PIN-84789
PH:4578954

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

Is it possible to achieve this in csvkit.


Solution

  • You can use 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
    

    to have

    A
    aaaaa
    23 rd., PIN-45789
    PH: 4578954
    
    F
    bbbbb
    23 rd., PIN-84789
    PH: 4578954
    
    D
    ccccc
    34 rd., PIN-45646
    PH: 7845663
    

    Some notes: