Effacer les filtres
Effacer les filtres

How can I add one character before each line of textfile?

12 vues (au cours des 30 derniers jours)
Bob Whiley
Bob Whiley le 26 Fév 2015
How can I add one character before each line of textfile and output a new textfile with the changes made?

Réponses (1)

Konstantinos Sofos
Konstantinos Sofos le 26 Fév 2015
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

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by