using regexp to parse specific line
Show older comments
Hi,
I am trying to use regexp to parse different values of multiple lines in a file. A line looks like this:
{"timestamp": 1666599517.7899299, "cell_log_wdm0": "[/dev/cdc-wdm0] Successfully got signal info\nLTE:\n\tRSSI: '-65 dBm'\n\tRSRQ: '-15 dB'\n\tRSRP: '-97 dBm'\n\tSNR: '-3.2 dB'\n5G:\n\tRSRP: '-108 dBm'\n\tSNR: '7.5 dB'\n\tRSRQ: '-13 dB'\n"}
And I would like to get the timestamp, the name of the cell (wdm0), LTE RSRP and 5G RSRP. I am trying to use regexp but I am unsure of how to use it, or if it is even the right approach.
I would appreciate any help. :-)
Accepted Answer
More Answers (1)
lines = readlines("c:\temp\lineLog.txt")
subLines = lines.split("\n").replace("\t","")
dataTs = subLines(:,1).split(",");
dataLte = array2table(subLines(:,3:6).extractAfter(":").replace("'","").strip,VariableNames=["RSSI" "RSRQ" "RSRP" "SNR"])
data5G = array2table(subLines(:,8:end-1).extractAfter(":").replace("'","").strip,VariableNames=["RSRP" "SNR" "RSRQ"])
table(dataTs,dataLte,data5G)
dataTs dataLte data5G
RSSI RSRQ RSRP SNR RSRP SNR RSRQ
_______________________________________________________________________________________________________ _______________________________________________ __________________________________
"{"timestamp": 1666599517.7899299" " "cell_log_wdm0": "[/dev/cdc-wdm0] Successfully got signal info" "-65 dBm" "-15 dB" "-97 dBm" "-3.2 dB" "-108 dBm" "7.5 dB" "-13 dB"
"{"timestamp": 1666599517.7899299" " "cell_log_wdm0": "[/dev/cdc-wdm0] Successfully got signal info" "-65 dBm" "-15 dB" "-97 dBm" "-3.2 dB" "-108 dBm" "7.5 dB" "-13 dB"
"{"timestamp": 1666599517.7899299" " "cell_log_wdm0": "[/dev/cdc-wdm0] Successfully got signal info" "-65 dBm" "-15 dB" "-97 dBm" "-3.2 dB" "-108 dBm" "7.5 dB" "-13 dB"
as long as the format is defined, this could be a starting point for your parser
I saved your example line (3times) to a text file before.
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!