필터 지우기
필터 지우기

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

조회 수: 4 (최근 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 CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by