How to extract specific text (eg. serial number) from single/multiple text file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (1)
Bob Thompson
am 2 Apr. 2019
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu String Parsing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!