editing large text file

1 visualización (últimos 30 días)
K.A.
K.A. el 6 de Sept. de 2018
Comentada: K.A. el 6 de Sept. de 2018
Hi,
In Notepad (or equivalent softwares) there is a feature that does search a character, edit it, and "Replace All".
How I can edit a text file by doing Replace All using Matlab?
Example: assume I have a text file that has 300 characters like "HjY". I want to replace all these characters with "HjY(i)" in an automated way.
  2 comentarios
KSSV
KSSV el 6 de Sept. de 2018
It depends on how the file is.....you have to attach a file format so that we can help you.
K.A.
K.A. el 6 de Sept. de 2018
Thanks KSSV,
In the attached file, there are variables that are listed from line number 4719 up to line 7402. Each line contains one variable. For instance, line number 7389 contains this variable "Q_input_C".
Now, I want to replace all these variables with themselves but after I add this suffix "(i)". All similar variables has to be replaced too. I will give an example to make it understandable.
Example: at line number 7317, there is this variable "I_line_upstream_B01_B03_C_r". I want to replace all variables in this file that are exactly similar to "I_line_upstream_B01_B03_C_r" with "I_line_upstream_B01_B03_C_r(i)". Then, I move to line 7318 and do the same thing and so on.
How can do this in a loop?

Iniciar sesión para comentar.

Respuestas (1)

ahmed nebli
ahmed nebli el 6 de Sept. de 2018
this is how is suggest you can do : -import your file/-use a for loop to search for 'H' and after it a 'j' and after it a 'Y' / if found : replace them with what you want
  1 comentario
K.A.
K.A. el 6 de Sept. de 2018
Good idea.. I will try to do it.. Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by