converting .txt file to .csv file with mixed delimiter
Show older comments
Hi there,
I want to convert the .txt file into .csv file. The file has mixed delimiter (Comma, tab) like this.

fileilename = '/Users/gulfcarbon2/Downloads/Modis Data/7da2190bbf_NSF_Rapid_HPLC_2018_AC.txt';
csvfile1 = readtable(filename, 'Delimiter','tab' );
writetable(csvfile1, 'seadasfile1.csv');
This is the code I wrote but the result is coming without any headerline (var1, var2 etc). Kindly help me out to write a function i can get the header in the 1st row and unit in the next. I have started coding in Matlab so every help is appriciated.
Thank you
Answers (3)
dpb
on 27 Jul 2022
1 vote
Using the import tool manually, just go to the section on 'delimiters' and check the comma as well as the identified blank -- it isn't tab-delimited but blank for the bulk of the file so the tab substitution didn't do anything, anyways.
1 Comment
Arnab Paul
on 28 Jul 2022
filename='/Users/gulfcarbon2/Downloads/Modis Data/7da2190bbf_NSF_Rapid_HPLC_2018_AC.txt';
data=readlines(filename);
data=strrep(data,char(9),',');
wwritematrix(data,'seadasfile1.csv','QuoteStrings',0); % correction; w R2022B and earlier
4 Comments
Arnab Paul
on 27 Jul 2022
dpb
on 27 Jul 2022
Arnab Paul
on 27 Jul 2022
dpb
on 27 Jul 2022
We can't do anything about testing anything with just images and you've not provided a sample (short) test file.
Nor have you specificied clearly what the end objective is???
3 Comments
dpb
on 27 Jul 2022
That's owing to however it is that the online run option thingie works about trying to find an attached file -- I dunno how that is supposed to be referenced, but has nothing to do with the code; simply says it can't find (or at least open) the file just by the file name.
I've never got it to work, but I've never tried much...
Arnab Paul
on 27 Jul 2022
Arnab Paul
on 27 Jul 2022
Categories
Find more on Text Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!