フィルターのクリア

How to extract specific text (eg. serial number) from single/multiple text file

2 ビュー (過去 30 日間)
Mun Chung Ho
Mun Chung Ho 2019 年 3 月 1 日
回答済み: Bob Thompson 2019 年 4 月 2 日
Hi guys,
I am currently having a log file where i required to extract the serial number and some information from the text log file. The serial number are not always in the same location of the text file, it may be at beginning or next few line of the text file. Is there anywhere i can extract the information like search/find function?

回答 (1 件)

Bob Thompson
Bob Thompson 2019 年 4 月 2 日
It is possible to use find or strcmp, but I think your best bet for this is to use regexp. If the serial number is in a consistent and unique format then you can simply search for a series of characters which match that format and extract it. It may not be the quickest, but it should work.
text = textscan('mytxtfile.txt','%s');
sn = regexp(text,'words* (\d\d\d\d\d\d\d\d\d\d\d) more words*','tokens'); % Should extract an 11 digit number buried in some words, adjust as needed

カテゴリ

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