How to extract text between two specific words using fread operation
Mostrar comentarios más antiguos
I have an data file where i need to extract the text between two specific words
<Edata
Line1
Line2
Edata>
I need to Extract the text content between two specific words e.g. "<Edata" and "Edata>" using fread operation. This file will be in unknown extension file (*.kcs), so i can read only by using file operations. Any Idea..?
Respuestas (2)
Image Analyst
el 11 de Ag. de 2014
Read the whole thing in using fread, which I assume you know how to do. Then
word1Location = strfind(theString, '<Edata');
word2Location = strfind(theString, 'Edata>');
inBetweenText = theString(word1Location+6:word2Location-1);
6 comentarios
Kanchibhotla Chandra Sekhar
el 11 de Ag. de 2014
Image Analyst
el 11 de Ag. de 2014
The code I gave did not work? It should work but you'll have to have the last line of code in a loop because the first two lines should return arrays with multiple starting and ending locations. Please show your code so we can debug it.
Kanchibhotla Chandra Sekhar
el 12 de Ag. de 2014
Editada: Kanchibhotla Chandra Sekhar
el 12 de Ag. de 2014
Image Analyst
el 12 de Ag. de 2014
I don't think you read my last comment at all. Did you? Where is your loop? And why are you searching for <FBD when you should be searching for <Edata?
Kanchibhotla Chandra Sekhar
el 12 de Ag. de 2014
Shirisha Acha
el 29 de Nov. de 2016
I was looking for the same answer as to how to loop it. Did you solve it yet? Can u plz share the code if so
Walter Roberson
el 29 de Nov. de 2016
theString = fileread(OldfilePath);
parts = regexp(theString, '(?<=<Edata\s*\n).*?(?=\nEdata>)', 'match');
I took the liberty here of removing the end-of-line character after and immediately before Edata . The meaning of "between" was not well defined here: what should happen if there is other text on the same line, like
<Edata %first one
line 1
line 2
Edata>
then should the '%first one' be extracted?
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!