Yesterday, I helped one of my alumnus to deal with a text file. The task is to extract some data from the file. The file is as blow:
mbgstatus v3.4.0 (c) Meinberg 2001-2009
GPS168PCI 027110027620 (FW 1.09) at port 0xDC00/0xDFA0, irq 23
Normal Operation, 11 sats in view, 6 sats used
Osc type: TCXO LQ, DAC cal: +500, fine: +48
Date/time: We, 2010-07-07 10:06:12.52 UTC
Signal: 100% (GPS)
Status info: Antenna is connected
Status info: Time is synchronized
Status info: *** Receiver pos. not verified
Last sync: We, 2010-07-07 10:06:01.00 UTC
Receiver Position:
lat: +52.6201 lon: -1.1239 alt: 163m
latitude: N 52 deg 37 min 12.36 sec
longitude: W 1 deg 07 min 25.87 sec
mbgstatus v3.4.0 (c) Meinberg 2001-2009
GPS168PCI 027110027620 (FW 1.09) at port 0xDC00/0xDFA0, irq 23
Normal Operation, 11 sats in view, 5 sats used
Osc type: TCXO LQ, DAC cal: +500, fine: +46
Date/time: We, 2010-07-07 10:07:12.64 UTC
Signal: 100% (GPS)
Status info: Antenna is connected
Status info: Time is synchronized
Status info: *** Receiver pos. not verified
Last sync: We, 2010-07-07 10:07:01.00 UTC
Receiver Position:
lat: +52.6201 lon: -1.1239 alt: 163m
latitude: N 52 deg 37 min 12.36 sec
longitude: W 1 deg 07 min 25.87 sec
mbgstatus v3.4.0 (c) Meinberg 2001-2009
GPS168PCI 027110027620 (FW 1.09) at port 0xDC00/0xDFA0, irq 23
Normal Operation, 10 sats in view, 5 sats used
Osc type: TCXO LQ, DAC cal: +500, fine: +47
Date/time: We, 2010-07-07 11:02:18.44 UTC
Signal: 100% (GPS)
Status info: Antenna is connected
Status info: Time is synchronized
Status info: Receiver position has been verified
Last sync: We, 2010-07-07 11:02:01.00 UTC
Receiver Position:
lat: +52.6202 lon: -1.1241 alt: 147m
latitude: N 52 deg 37 min 12.56 sec
longitude: W 1 deg 07 min 26.85 sec
There are so so many segments of this kid of paragraphs. The data to extract is the numbers after lat and lon marks in each paragraph which means the latitude and longitude of something which come from a GPS device.
One more thing is that only data that has been verified is useful, that is to say, only data in the paragraph the contains "Status info: Receiver position has been verified" is useful. The target file is to be like this:
+52.6202 -1.1241
+52.6202 -1.1241
+52.6202 -1.1241
Of course,actual data are different.
At first he want to extract the data using Matlab, I don't know how to use Matlab to do this kind of stuff. Since real time process is not needed, I thought extract data use some other tools will be better. At last I thought VIM is a good candidate cause I don't need to write any language to do this, another reason I chose VIM is because I am learning VIM so I want to use it as much as I can.
My strategy was quite simple, that it to delete all the stuffs that I don't need. I first deal with a single paragraph, then repeat the operation using macro. Operation is as below:
- Search "has been verified" using /has been verified, delete this line
- Start record a macro and delete two lines from here"
- Move to the next line
- Delete to the next match of line contains "has been verified" (shift V, n, d) and stop record the macro
- Repete this operation use the macro recorded
- Using block mode to delete all the columns that are not needed
That's all, I think there must be a better way to do this, someone knows?
No comments:
Post a Comment