Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Adding specific section of one text file to another

1 vue (au cours des 30 derniers jours)
Abram Aguilar
Abram Aguilar le 12 Juil 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have two text files, one with 523 lines and another with 516 lines. Line 14 of text file 1 matches line 5 of text file 2. I would like to merge everything from lines 1-13 in text file 1 to before line 5 of text file 2. However, I do not want to do it using the visdiff function. Any suggestions? Unfortunately I am unable to share the code or contents of the text files.

Réponses (1)

Cristian Garcia Milan
Cristian Garcia Milan le 12 Juil 2019
Modifié(e) : Cristian Garcia Milan le 14 Juil 2019
Hi Abraham Aguilar,
Like I don't have your text (or an example of that one with random words) I'm going to suposse that you have a string with differents line breaks. A line break is usually a
char(10) or newline
So you can search for these char.
linebreaks1 = strfind(str1,char(10));
linebreaks2 = strfind(str2,char(10));
Newtext = [str2(1:linebreaks1(4)),str1(1:linebreaks1(13)-1,str2(linebreaks2(4):end)]; %I have suposse that you want the 4 first lines of str2 before the str1 lines.

Cette question est clôturée.

Produits


Version

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by