find specific text in a text file

1 vue (au cours des 30 derniers jours)
amin
amin le 13 Fév 2020
Commenté : amin le 17 Fév 2020
Hi
In the text file below, I want to obtain everything between "|[" and "]|".
system
component1 |[ b,a,d, w,e,r ]| component2
endsystem
so the output is : b,a,d, w,e,r
Thanks in advance.

Réponse acceptée

Srivardhan Gadila
Srivardhan Gadila le 16 Fév 2020
Please refer to the functions fileread & regexp.
Let's assume that the following content
"system
component1 |[ b,a,d, w,e,r ]| component2
endsystem"
is in a text file named textFile.txt then the following code might help you:
textChar = fileread("textFile.txt");
startIndex = regexp(textChar,'|[');
endIndex = regexp(textChar,']|');
requiredOutput = textChar(startIndex+1:endIndex-2)
  1 commentaire
amin
amin le 17 Fév 2020
Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by