Can REGEXP be utilized to ignore specific numerical values in a text file?
Show older comments
I’ve got a text file that contains thousands of lines such as the following:
Code: 1 Firm ID: 5 Time Tag: 58000.00000000
Board ID: 1 SUB ID: 4 Error ID: 0 Abort: 0
Code: 6 Firm ID: 1 Time Tag: 58001.50000000
Board ID: 4 SUB ID: 5 Error ID: 1 Abort: 1
Code: 1 Firm ID: 1 Time Tag: 58002.00000000
Board ID: 4 SUB ID: 2 Error ID: 0 Abort: 1
Code: 3 Firm ID: 5 Time Tag: 58003.50000000
Board ID: 2 SUB ID: 2 Error ID: 0 Abort: 1
Code: 1 Firm ID: 4 Time Tag: 58004.00000000
Board ID: 9 SUB ID: 7 Error ID: 0 Abort: 0
Code: 1 Firm ID: 5 Time Tag: 58005.50000000
Board ID: 2 SUB ID: 1 Error ID: 0 Abort: 1
Code: 1 Firm ID: 5 Time Tag: 58006.00000000
Board ID: 7 SUB ID: 6 Error ID: 0 Abort: 0
Code: 9 Firm ID: 1 Time Tag: 58007.50000000
Board ID: 5 SUB ID: 3 Error ID: 0 Abort: 0
I’m attempting to parse out the time tag value and abort value for each SUB ID – except for SUB ID values 2 and 1.
I’m using the following code to parse out the time tags and abort values for ALL of the SUB IDs:
exp = '(?<=Time Tag: )([\d\.]+).+?(?<=SUB ID:[ ]+)(\d+).+?(?<=Abort:[ ]+)(\d+)';
tokens = regexp(buffer, exp, 'tokens');
OAM_data = reshape(str2double([tokens{:}]), 3, []).';
This results in the following 8 x 3 array:
58000 4 0
58001.5000000000 5 1
58002 2 1
58003.5000000000 2 1
58004 7 0
58005.5000000000 1 1
58006 6 0
58007.5000000000 3 0
If possible, how can I utilize the REGEXP command to parse out the time tags and abort values for all SUB IDs except for SUB IDs 1 and 2?
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!