how to print a specific potion of a text file

hi... i have a text file which has different headings like 1. introduction 2. circuit analysis etc... i want to display all the lines lying between these headings 1 & 2

 Réponse acceptée

filecontent = fileread('YourFile.txt');
h1pos = strfind(filecontent, '1. introduction');
h2pos = strfind(filecontent, '2. circuit analysis');
disp( filecontent(h1pos(1) : h2pos(1)-1) );

4 commentaires

Ayushi Saxena
Ayushi Saxena le 30 Déc 2015
Thank you Walter... :)
Ayushi Saxena
Ayushi Saxena le 30 Déc 2015
further i need to store the displayed result in a variable...
so i did [output] = disp( filecontent(h1pos(1) : h2pos(1)-1) ).
but it shows error as too many output arguments. please help me regarding this.
output = filecontent(h1pos(1) : h2pos(1)-1);
Note that this will be a single string that includes newline characters and possibly carriage return characters as well. What form are you hoping for considering you have multiple lines?
Ayushi Saxena
Ayushi Saxena le 30 Déc 2015
thanks.. it worked .. basically i have a pdf file which i have converted into txt format so on that basis i was trying to do that.....

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Text Analytics Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by