12
1
Slightly more than an inverse of this.
In: Multi-line DSV data and a single delimiter character. The DSV may be taken as a file, a filename, line-break separated string, list of strings, etc. All records have the same number of fields, and no field is empty. Data does not contain the delimiter character and there is no quoting or escaping mechanism.
Out: A data structure representing the DSV, e.g. a list of lists of strings or a matrix of strings.
Examples
["here is,some,sample","data,delimited,by commas"]
and ","
:
[["here is","some","sample"],["data","delimited","by commas"]]
["hello;\"","\";world","\";\""]
and ";"
:
[["hello","\""],["\"","world"],["\"","\""]]
(escapes because this example uses JSON)
["to be or not","that is the question"]
and " "
:
[["to","be","or","not"],["that","is","the","question"]]
So just to clarify, we simply split each item at instances of the given char? – ETHproductions – 2017-02-28T19:42:56.617
@ETHproductions That's right. – Adám – 2017-02-28T19:45:30.177
How should we split the strings if the first or last character is the delimiter?
",for,example,this,string,"
– G B – 2017-03-01T10:28:45.923@GB no field is empty – Adám – 2017-03-01T10:35:48.533
So we can assume it won't happen? – G B – 2017-03-01T10:42:08.583
@GB Yes, as stated in the OP. – Adám – 2017-03-01T10:42:40.300
Can the output be a linebreak-separated string too? i.e. would
to,be,or,not\nthat,is,the,question
be a valid output to your third example? – Aaron – 2017-03-01T10:55:00.550@Aaron Only if that is the normal way to represent/print lists in your language. – Adám – 2017-03-01T10:56:17.910
@Aaron I was thinking of asking the same, since in sed the natural representation of a list is a collection of lines. As for list of lists, this is less clear, sed has no data types anyway, so
to,be,or,not\nthat,is,the,question
is I guess reasonable for this challenge. That, or each field on separate lines. – seshoumara – 2017-03-03T21:14:40.447@seshoumara since the target is CSV, the inner list has to be comma-separated anyway, otherwise I guess any character of the default
IFS
would have been a good pick even ifsed
does not care about them. I was asking for><>
which can only output characters and numbers. – Aaron – 2017-03-03T23:31:19.133