How can I add one character before each line of textfile?
8 次查看(过去 30 天)
显示 更早的评论
How can I add one character before each line of textfile and output a new textfile with the changes made?
0 个评论
回答(1 个)
Konstantinos Sofos
2015-2-26
Hi Bob,
What about this:
fid1 = fopen('file1.txt');
fid2 = fopen('file2.txt','w');
tline = fgets(fid1);
Character2add = 'xx_'; % here put the character to be added
while ischar(tline)
disp(tline)
fprintf(fid2,'%s %s\n',Character2add,tline);
tline = fgets(fid1);
end
fclose(fid1);
fclose(fid2);
Regards
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!