4 ms·
This gratuitously uses a "sentinel" (octal 004) which is a technique that I sometimes use when converting more complex input to CSV. I regularly convert (bad)
by gwu78 11y ago
This gratuitously uses a "sentinel" (octal 004) which is a technique that I sometimes use when converting more complex input to CSV.
I regularly convert (bad) HTML and other nonsense to CSV, and this "challenge" was a little too easy; let's have some more difficult CSV tasks!
[ -f data.json ]||
ftp -4o data.json https://gist.githubusercontent.com/jorin-vogel/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json &&
{
a=$(echo b|tr b '\004') ;
exec sed '
1i\
name,creditcard
/creditcard\":\"./!d;
s/.*name\":\"//;
s/\"/,/;
s/'"$a"'//g;
s/creditcard\":\"/'"$a"'/
s/,.*'"$a"'/,/;
s/\".*//;
' data.json
}