I have a txt files with some lines containing GPS data, which I need to shorten.
So I have
5|{"mResults":0.0|0.0|"mProvider":"fused"|"mDistance":0.0|"mTime":1395061255413|"mAltitude":161.0|"mLongitude":29.0459152|"mLon2":0.0|"mLon1":0.0|"mLatitude":41.0854122|"mLat1":0.0|"mLat2":0.0|"mInitialBearing":0.0|"mHasSpeed":true|"mHasBearing":false|"mHasAltitude":true|"mHasAccuracy":true|"mAccuracy":15.0|"mSpeed":0.425211|"mBearing":0.0}|1395061255413
and I need to extract only the coordinates, so convert it into this :
29.0459152|41.0854122
Turns out I need this:
GPS|29.0459152|41.0854122|0|1395061255413
Please note that I need to :
GPS|
in front, and |0
at the end. |1395061255413
How can I do this with Notepad++?
Thanks for any help !
Here is how you could do that in Notepad++ :
Regular expression
in the Search mode
section .*?"mLongitude":(\\d+(?:\\.\\d+)?).*?"mLatitude":(\\d+(?:\\.\\d+)).*
\\1|\\2
How it works:
The regex pattern featured in my answer extracts the values for the longitude and latitude from each line and replaces the whole line by:
mLongitude
value, |
" and mLatitude
value. Would you like to have this pattern explained in more details, please check out this permalink on regex101 .
EDIT:
To include the timestamp you're referring to, you need to use this regex:
.*?"mLongitude":(\d+(?:\.\d+)?).*?"mLatitude":(\d+(?:\.\d+)).*\|(\d+)
Then, you just have to change the formatting of your replacement string to this:
GPS|\1|\2|0|\3
You probably got that already but let's still write down the complete usable solution ;)
I hope this helps!
I solved my problem by this :
search:
.*?"mTime":(\d+(?:\.\d+)?).*?"mLongitude":(\d+(?:\.\d+)).*?"mLatitude":(\d+(?:\.\d+)).*
replace :
GPS|\2|\3|0|\1
But this is because the same data (timestamp) was also inside the string. So this does not extract the timestamp from the end, but from the middle of the string.
So if @ccjmne edits the answer that extracts it from the end, I will accept that answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.