MATLAB: How to delete header from a .txt file and save it

remove headersave new filetxt file

I have a text file like this one:
element, unit, refTime, validTime, (62.000000,-6.250000)
HTSGW, [m], 197901010000, 197901010000, 0.000
HTSGW, [m], 197901010000, 197901010300, 0.220
HTSGW, [m], 197901010000, 197901010600, 0.420
HTSGW, [m], 197901010000, 197901010900, 0.560
HTSGW, [m], 197901010000, 197901011200, 2.190
I just want to remove the header and then save the file in the same .txt file without the header.
I may use the next script, shown in other forums, however I cannot save the generated list.
fid = fopen(Text);
tline = fgetl(fid);
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
end
fclose(fid);
I wish someone could help me. Thanks.

Best Answer

fid=fopen('file.txt')
s=textscan(fid,'%s%s%s%s%s','headerlines',1)
fclose(fid)
ss=[s{:}]
fid1=fopen('file.txt','w')
for k=1:size(ss,1)
fprintf(fid1,'%s%s%s%s%s\r\n',ss{k,:})
end
fclose(fid1)