How can I edit and external text ('.txt') file?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a text file, and I want to edit a value of an especific line.
For example, the 17th line of the text file is:
11XX0001 0 24500. -1. 1.E3
and I want to edit it for
11XX0001 0 357. -1. 1.E3
While the rest of the file shall be the same. Thank you very much, in advance!
0 comentarios
Respuestas (1)
Walter Roberson
el 23 de Sept. de 2016
Because your replacement is a different size than your input, you will need to create a new output file with the modifications; you will not be able to make the change "in place".
Open the input file, open the output file, loop 16 times using fgets() from input and fwrite() to output. fgets the 17th line and make the change to the string as required. Then fwrite() the new string to the output. Then loop over the rest of the file, fgets() and fwrite(). Finally fclose() both files.
0 comentarios
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!