- read the entire file to a character vector
- replace "#@#@#" by newline
- replace "'~'" by comma (I use "" to avoid escape characters)
- parse the resulting string with textscan() (for some reason readtable doesn't take strings.)
How to read in large text file with special delimiters?
4 views (last 30 days)
Ricardo Lopez A. on 23 Apr 2021
Is there a way to read data from a text file with the following format per row:
Thus, the column delimiter is '~', and the row delimiter is #@#@#.
Further, missing/null values are represented by two columns delimiters '~''~', for example:
Is there any way to specify your own row and column delimiters to be able to read in this data?
Thanks a lot in advance!
per isakson on 24 Apr 2021
Edited: per isakson on 24 Apr 2021
"Is there any way to specify your own row and column delimiters to be able to read in this data?" No, I don't think so.
How large is the text file? I assume it fits in a fraction of the physical memory (RAM) of your computer.
I ussume that the column delimiter is the three character vector: '~'
chr = fileread( 'cssm.txt' );
str = strrep( chr, "#@#@#", newline );
str = strrep( str, "'~'", "," );
cac = textscan( str, '%s%f%f%f%f%f%f%f%f', 'Delimiter',',' );
where cssm.txt contains twentyfile copies of your first example in a single row.