How to import a CSV file of files that have space delimited values?

I've received a data file in a mysterious ".pos" format. It consists of many lists that are separated by the space character; these are in turn separated by commas,e.g., { {a b c},{d e f},...} Apparently this file can be imported but can not fully exploited. For example, filename[[2]] can extract {d e f}, but neither Take, Drop or Part work to extract a particular value of each, or any, space delimited list. How can such values be extracted?

Additionally, I've not been able to Google any information of ".pos" file formats. Is this format known to Mathematica/Wolfram Language?

• Probably because they are imported as strings. Try ToExpression[filename] – Rohit Namjoshi Jan 11 at 3:59
• I also thought so, but StringQ[filename] was False. ".pos" files must have some sort of Delimiter Spaced Values (DSV) format. Thanks anyway. – stqnt Jan 11 at 13:14

I'd like to point out that there is the import/export format "Table" that can be customized to address different kinds of delimiters. Here is an import example that treats spaces as field separators and commas as line separators:

Import["file.pos", "Table",
"FieldSeparators" -> " ",
"LineSeparators" -> ","
]


If your data is really stored in the format {{a b c},{d e f},...}, it should be possible to be imported with the following:

DeveloperToPackedArray[
Import["file.pos", "Table", "FieldSeparators" -> " ",
"LineSeparators" -> {"{", "},{", "}"}][[3 ;; -3]]
]


Unfortunately, I cannot test this because you have not provided any example file. BTW., I assumed that the data in the file is numeric; even that is not clear from your problem description.

• Import::erropts: The value {"{","}"} specified for the option "CurrencyTokens" is invalid. – Somos Jan 12 at 9:48
• Okay, I stress it once more: We need an example file or at least an example string from that file here. – Henrik Schumacher Jan 12 at 9:58
• Yes, the data is numeric, and yes, Import["filename.pos", "Table"] worked. – stqnt Jan 12 at 16:36

The following worked: Import["filename.pos", "Table"] worked.

The following code should be close to what you want:

StringSplit[ StringReplace[ Import[filename, "CSV"][[1]],
{"{" -> "", "}" -> ""}]] // ToExpression


You may need to tweak it if it does not do exactly what you want. An example of use is

stringfile = "{{a b c},{d e f},{g}}";
StringSplit[ StringReplace[ ImportString[stringfile, "CSV"][[1]],
{"{" -> "", "}" -> ""}]] // ToExpression


Yielding the result

{{a, b, c}, {d, e, f}, {g}}
`