find specific text in a text file

2 ビュー (過去 30 日間)
amin
amin 2020 年 2 月 13 日
コメント済み: amin 2020 年 2 月 17 日
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.

採用された回答

Srivardhan Gadila
Srivardhan Gadila 2020 年 2 月 16 日
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 件のコメント
amin
amin 2020 年 2 月 17 日
Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by