append the content of a txt to the end of a txt....
Show older comments
how can i append the content of content.txt to the end of the 33.txt
i think the code should be something like that...
clc
fid1 = fopen('C:\Users\Mr Andrew\Desktop\content.txt', 'r');
fid = fopen('C:\Users\Mr Andrew\Desktop\33.txt', 'a');
for k = 1:5
fprintf(fid,'fid1 \r\n') ;
end
fclose(fid);
fclose(fid1);
thank you
Accepted Answer
More Answers (1)
dpb
on 26 Aug 2013
Which OS? Under Win, I'd just use
system('copy 33.txt+content.txt')
To make a new target file, also specify a destination filename...
system('copy 33.txt+content.txt bigtextfile.txt')
I'm certain the other OS has something similar but not positive about syntax.
Inside Matlab your proposed script doesn't work as written -- you open the one for append and the other for read access as have but then must read the other in explicitly and write out -- which is the easiest way to do that is dependent on the content in the file. I'm not certain what the loop w/ upper limit of 5 is trying to do???
fi = fopen('C:\Users\Mr Andrew\Desktop\content.txt', 'r');
fo = fopen('C:\Users\Mr Andrew\Desktop\33.txt', 'wa');
while ~feof(fi)
l=fgetl(fi); % get line from input
fprintf(fp,'%s\n',l); % write to output
end
fi=fclose(fi);
fo=fclose(fo);
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!