I'm very much an amateur with grep.

How do I find the optional minus and put it in the subpattern?

I want to grab the time in the following and then use it for the name.
Multiple names in the document. I seem to have it except for finding
the optional minus sign that can occur with ele, lat and lon. I've
only tried for lon so far and once I have the answer I'll expand it to
the others. I get errors if I put the minus within the parentheses. I
tried a -? within the parentheses too. How do I find the optional
minus and put it in the subpattern?

Typical document snippet (.gpx which is XML):

  <name>ACTIVE LOG133853</name>
  <trkseg>
   <trkpt lat="33.846701" lon="-118.387723">
    <ele>16.652</ele>
    <time>2010-05-15T20:38:53Z</time>
   </trkpt>
  </trkseg>
 </trk>
 <trk>
  <name>ACTIVE LOG133905</name>
  <trkseg>
   <trkpt lat="33.846273" lon="-118.387273">
    <ele>16.697</ele>
    <time>2010-05-15T20:39:05Z</time>
   </trkpt>
   <trkpt lat="33.846477" lon="-118.387105">
    <ele>16.652</ele>
    <time>2010-05-15T20:39:10Z</time>
   </trkpt>
   <trkpt lat="33.846606" lon="-118.387037">
    <ele>17.152</ele>
    <time>2010-05-15T20:39:16Z</time>
   </trkpt>
   <trkpt lat="33.846673" lon="-118.387212">
    <ele>17.294</ele>
    <time>2010-05-15T20:39:23Z</time>
   </trkpt>
   <trkpt lat="33.846595" lon="-118.387456">
    <ele>16.901</ele>
    <time>2010-05-15T20:39:29Z</time>
   </trkpt>

My find:
<name>ACTIVE LOG[1-9]+</name>
  <trkseg>
   <trkpt lat\=\"(\d+\.\d+)\" lon\=\"\-(\d+\.\d+)\">
    <ele>(\d+\.\d+)</ele>
    <time>(.*?)</time>
   </trkpt>

My replace
<name>\4 ACTIVE LOG</name>
  <trkseg>
   <trkpt lat=\"\1\" lon=\"\2\">
    <ele>\3</ele>
    <time>\4</time>
   </trkpt>

This doesn't give errors but I can't find the optional minus and put
it back in the replace. Maybe I'm going at this all wrong.

Thanks for any help.

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.

Reply via email to