I have a GPX-file form my gps. I want to delete sections of it. a part of it is: <name>001</name>
<sym>Dot</sym>
<type>School</type>
<extensions>
<label xmlns="http://www.topografix.com/GPX/gpx_overlay/0/3">
</label>
</extensions>
</wpt>
<wpt lat="55.54934616" lon="11.94559830">
<ele>48.430</ele>
<time>2008-05-07T22:09:25Z</time>
<name>002</name>
<sym>Dot</sym>
<type>School</type>
<extensions>
<text xmlns="http://www.topografix.com/GPX/gpx_style/0/2">
<family generic="sans-serif">
<face>Arial</face>
</family>
</text>
</extensions>
</wpt>
<trk>I have tried to make a script in Perl to read the gpx-file line by line:
#!C:\\perl/bin/perl.exe
open(IndFil,"avnso1.gpx")|| die;
while ($line = <IndFil>)
{
print $line;
}
close(IndFil);
-but of course, that's not enough.How do I delete the code between <extensions> and </extensions> - and the word <extensions></extensions>?
I would like it in Peal or PHP.
I haven't done perl for a looooonnng time, so my attempt
below is probably totally rubbish, but try it if you want.#!C:\\perl/bin/perl.exe open(IndFil,"avnso1.gpx")|| die; $inExtensions = 0 while ($line = <IndFil>) { if ($line == "<extensions>") $inExtensions = 1 else if ($line == "</extensions>") $inExtensions = 0 else if (!($inExtensions)) print $line; } close(IndFil);
Thank you!
I have made some corrections for syntaxerros, but it does not work. It sees that alle the lines go into the: if ($line == "<extensions>")Here is the full code:
#!C:\\perl/bin/perl.exe
open(IndFil,"avnso1.gpx")|| die;
$inExtensions = 0;
while ($line = <IndFil>)
{
if ($line == "<extensions>") {
$inExtensions = 1;
}
elsif ($line == "</extensions>"){
$inExtensions = 0;
}
elsif (!($inExtensions)){
print $line;
}
else
{
print "no hits";
}
}
close(IndFil);
If you include 'Perl' in the subject, it will make it easier for us to know what you need. Here's a very simple 1 liner:
C:\>perl -ni.bak -e "print unless m|<extensions>| .. m|</extensions>|" avnso1.gpxOr, if youwant that in script form:
#!/usr/bin/perl use warnings; use strict; $^I = '.bak'; while ( <> ) { print unless m|<extensions>| .. m|</extensions>|; }
I need it a script. But where do I place the gpx-filename: anvso1.gpx in the script?
If you use the script I posted, then you would pass the filename as an argument to the script. Like so,
C:\>script.pl anvso1.gpx
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |