Visit Our UNIX and Linux User Community


Filter a .kml file (xml) with data set from text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter a .kml file (xml) with data set from text file
# 1  
Old 10-18-2011
Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file

Code:
11951
11952
74014
11964
11965
11969
11970
11971
11972
60149
74018
74023
86378
11976
11980
11983
11984
11987
74026
74093
86380

this is example from my kml file

Code:
<Placemark>
    <name>CE CATOLICO RICARDO POMA</name>
    <ExtendedData><SchemaData schemaUrl="#escuelas">
        <SimpleData name="DEPARTAMEN">SAN SALVADOR</SimpleData>
        <SimpleData name="MUNICIPIO">TONACATEPEQUE</SimpleData>
        <SimpleData name="CODIGO">11951</SimpleData>
        <SimpleData name="ESTATUS"></SimpleData>
        <SimpleData name="LAMBERTX">484840</SimpleData>
        <SimpleData name="LAMBERTY">297529</SimpleData>
        <SimpleData name="MODALIDAD">SUBV</SimpleData>
        <SimpleData name="NOMBRE_ESC">CE CATOLICO RICARDO POMA</SimpleData>
        <SimpleData name="DIRECCION">RESIDENCIAL  LIBERTAD CALLE PRINCIPAL</SimpleData>
        <SimpleData name="CASERIO"></SimpleData>
        <SimpleData name="CANTON"></SimpleData>
        <SimpleData name="TELEFONO">25020215</SimpleData>
        <SimpleData name="TURNO1">480</SimpleData>
        <SimpleData name="TURNO2">160</SimpleData>
        <SimpleData name="TURNO3"></SimpleData>
        <SimpleData name="TOTALMATRI">640</SimpleData>
        <SimpleData name="AULASOK">15</SimpleData>
        <SimpleData name="AULASREG"></SimpleData>
        <SimpleData name="AULASMALAS"></SimpleData>
        <SimpleData name="TOTALAULAS">15</SimpleData>
        <SimpleData name="AREA">3507</SimpleData>
        <SimpleData name="ENERGIA">SI</SimpleData>
        <SimpleData name="AGUAP">SI</SimpleData>
        <SimpleData name="AGUAN">SI</SimpleData>
        <SimpleData name="LATGRADOS">13</SimpleData>
        <SimpleData name="LATMIN">47</SimpleData>
        <SimpleData name="LATSEG">59</SimpleData>
        <SimpleData name="LONGRADOS">89</SimpleData>
        <SimpleData name="LONMIN">8</SimpleData>
        <SimpleData name="LONSEG">25</SimpleData>
        <SimpleData name="ALTURA">489</SimpleData>
        <SimpleData name="EPE">3</SimpleData>
        <SimpleData name="CAN_SATELI">7</SimpleData>
        <SimpleData name="FECHA">2005/11/22</SimpleData>
        <SimpleData name="CONTRATO">693/2005</SimpleData>
        <SimpleData name="EXPR1"></SimpleData>
        <SimpleData name="EXPR2"></SimpleData>
        <SimpleData name="TECNICO_RE">JOSE DAVID SALGADO</SimpleData>
        <SimpleData name="A_O">2006</SimpleData>
        <SimpleData name="longitud">-89.1402778</SimpleData>
        <SimpleData name="latitud">13.7997222</SimpleData>
    </SchemaData></ExtendedData>
      <Point><coordinates>-89.1402079085575,13.798839408878646</coordinates></Point>
  </Placemark>
  <Placemark>
    <name>CE URBANIZACION CUMBRES DE SAN BARTOLO</name>
    <ExtendedData><SchemaData schemaUrl="#escuelas">
        <SimpleData name="DEPARTAMEN">SAN SALVADOR</SimpleData>
        <SimpleData name="MUNICIPIO">TONACATEPEQUE</SimpleData>
        <SimpleData name="CODIGO">74014</SimpleData>
        <SimpleData name="ESTATUS">Revisar</SimpleData>
        <SimpleData name="LAMBERTX">487889</SimpleData>
        <SimpleData name="LAMBERTY">289859</SimpleData>
        <SimpleData name="MODALIDAD">ACE</SimpleData>
        <SimpleData name="NOMBRE_ESC">CE URBANIZACION CUMBRES DE SAN BARTOLO</SimpleData>
        <SimpleData name="DIRECCION">FINAL CALLE PRINCIPAL COL LA CAMPANERA</SimpleData>
        <SimpleData name="CASERIO"></SimpleData>
        <SimpleData name="CANTON">LA UNION</SimpleData>
        <SimpleData name="TELEFONO">22942617</SimpleData>
        <SimpleData name="TURNO1">245</SimpleData>
        <SimpleData name="TURNO2">126</SimpleData>
        <SimpleData name="TURNO3"></SimpleData>
        <SimpleData name="TOTALMATRI">371</SimpleData>
        <SimpleData name="AULASOK">11</SimpleData>
        <SimpleData name="AULASREG"></SimpleData>
        <SimpleData name="AULASMALAS"></SimpleData>
        <SimpleData name="TOTALAULAS">11</SimpleData>
        <SimpleData name="AREA">2500</SimpleData>
        <SimpleData name="ENERGIA">SI</SimpleData>
        <SimpleData name="AGUAP">SI</SimpleData>
        <SimpleData name="AGUAN">SI</SimpleData>
        <SimpleData name="LATGRADOS">13</SimpleData>
        <SimpleData name="LATMIN">43</SimpleData>
        <SimpleData name="LATSEG">50</SimpleData>
        <SimpleData name="LONGRADOS">89</SimpleData>
        <SimpleData name="LONMIN">6</SimpleData>
        <SimpleData name="LONSEG">43</SimpleData>
        <SimpleData name="ALTURA">749</SimpleData>
        <SimpleData name="EPE">3</SimpleData>
        <SimpleData name="CAN_SATELI">3</SimpleData>
        <SimpleData name="FECHA">2005/11/22</SimpleData>
        <SimpleData name="CONTRATO">693/2005</SimpleData>
        <SimpleData name="EXPR1"></SimpleData>
        <SimpleData name="EXPR2"></SimpleData>
        <SimpleData name="TECNICO_RE">JOSE DAVID SALGADO</SimpleData>
        <SimpleData name="A_O">2006</SimpleData>
        <SimpleData name="longitud">-89.1119444</SimpleData>
        <SimpleData name="latitud">13.7305556</SimpleData>
    </SchemaData></ExtendedData>
      <Point><coordinates>-89.111976076037394,13.729521887363052</coordinates></Point>
  </Placemark>
  <Placemark>
    <name>COLEGIO PROFESORA RAQUEL CHAVEZ MENDEZ</name>
    <ExtendedData><SchemaData schemaUrl="#escuelas">
        <SimpleData name="DEPARTAMEN">SAN SALVADOR</SimpleData>
        <SimpleData name="MUNICIPIO">TONACATEPEQUE</SimpleData>
        <SimpleData name="CODIGO">21306</SimpleData>
        <SimpleData name="ESTATUS"></SimpleData>
        <SimpleData name="LAMBERTX">488932</SimpleData>
        <SimpleData name="LAMBERTY">289316</SimpleData>
        <SimpleData name="MODALIDAD">PRIV</SimpleData>
        <SimpleData name="NOMBRE_ESC">COLEGIO PROFESORA RAQUEL CHAVEZ MENDEZ</SimpleData>
        <SimpleData name="DIRECCION">URB CIMA DE SAN BARTOLO 2 FINAL C PPAL</SimpleData>
        <SimpleData name="CASERIO"></SimpleData>
        <SimpleData name="CANTON"></SimpleData>
        <SimpleData name="TELEFONO">75128749</SimpleData>
        <SimpleData name="TURNO1">157</SimpleData>
        <SimpleData name="TURNO2">130</SimpleData>
        <SimpleData name="TURNO3"></SimpleData>
        <SimpleData name="TOTALMATRI">287</SimpleData>
        <SimpleData name="AULASOK">0</SimpleData>
        <SimpleData name="AULASREG"></SimpleData>
        <SimpleData name="AULASMALAS">8</SimpleData>
        <SimpleData name="TOTALAULAS">8</SimpleData>
        <SimpleData name="AREA">200</SimpleData>
        <SimpleData name="ENERGIA">SI</SimpleData>
        <SimpleData name="AGUAP">SI</SimpleData>
        <SimpleData name="AGUAN">SI</SimpleData>
        <SimpleData name="LATGRADOS">13</SimpleData>
        <SimpleData name="LATMIN">43</SimpleData>
        <SimpleData name="LATSEG">32</SimpleData>
        <SimpleData name="LONGRADOS">89</SimpleData>
        <SimpleData name="LONMIN">6</SimpleData>
        <SimpleData name="LONSEG">9</SimpleData>
        <SimpleData name="ALTURA">659</SimpleData>
        <SimpleData name="EPE">5</SimpleData>
        <SimpleData name="CAN_SATELI">4</SimpleData>
        <SimpleData name="FECHA">2005/11/22</SimpleData>
        <SimpleData name="CONTRATO">693/2005</SimpleData>
        <SimpleData name="EXPR1"></SimpleData>
        <SimpleData name="EXPR2"></SimpleData>
        <SimpleData name="TECNICO_RE">JOSE DAVID SALGADO</SimpleData>
        <SimpleData name="A_O">2006</SimpleData>
        <SimpleData name="longitud">-89.1025000</SimpleData>
        <SimpleData name="latitud">13.7255556</SimpleData>
    </SchemaData></ExtendedData>
      <Point><coordinates>-89.102330554975865,13.72461769675952</coordinates></Point>
  </Placemark>

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 10-18-2011 at 09:20 PM.. Reason: code tags, please!
# 2  
Old 10-18-2011
Code:
nawk -F'[<>]' 'FNR==NR{f1[$1];next} /SimpleData name/ {if($3 in f1)print;next}1' textFileWithCodes myKMLfile

These 2 Users Gave Thanks to vgersh99 For This Post:
# 3  
Old 10-18-2011
Quote:
Originally Posted by vgersh99
Code:
nawk -F'[<>]' 'FNR==NR{f1[$1];next} /SimpleData name/ {if($3 in f1)print;next}1' textFileWithCodes myKMLfile

So good idea. Smilie

Code:
awk -F'[<>]' 'FNR==NR{f1[$1];next} /SimpleData name/&& !($3 in f1) {next}1' textFileWithCodes myKMLfile

# 4  
Old 10-19-2011
thank you by your soon response
however
I have a .kml file. So I want filter this .kml file to get entrys
Code:
<Placemark>
.
.
.
</Placemark>

where each tag <SimpleData name="CODIGO">XXXXX</SimpleData>
is the filter to evaluate
where CODIGO= to any code that appears in my textFileWithCode

So my output myKMLfile must have a entry for each code that appears textFileWithCode

So myKMLfile will be as appears below
Code:
<Placemark>
.
.
.
<SimpleData name="CODIGO">88156</SimpleData>

.
.
.
</SchemaData></ExtendedData>
 <Point><coordinates>-89.1402079085575,13.798839408878646</coordinates></Point>
</Placemark>
<Placemark>
.
.
.
<SimpleData name="CODIGO">11952</SimpleData>

.
.
.
</SchemaData></ExtendedData>
 <Point><coordinates>-89.1402079085575,13.798839408878646</coordinates></Point>
</Placemark>

---------- Post updated 10-19-11 at 01:31 AM ---------- Previous update was 10-18-11 at 10:26 PM ----------

I will test with this script however don't wok
I need generate a output file with entrys
Code:
 <Placemark>
.
.
.
<SimpleData name="CODIGO">88156</SimpleData>

.
.
.
<Placemark>

for each code that is in code.txt file

Can you help me?

Last edited by Franklin52; 10-19-2011 at 05:00 AM.. Reason: Please use code tags, thank you
# 5  
Old 10-19-2011
Quote:
Originally Posted by pcoj33
---------- Post updated 10-19-11 at 01:31 AM ---------- Previous update was 10-18-11 at 10:26 PM ----------

I will test with this script however don't wok
I need generate a output file with entrys
Code:
 <Placemark>
.
.
.
<SimpleData name="CODIGO">88156</SimpleData>

.
.
.
<Placemark>

for each code that is in code.txt file

Can you help me?
I don't think I can... I don't understand what's wrong with the posted code and/or what you're after...
Please try to describe what doesn't work and what you're expecting once more.
# 6  
Old 10-19-2011
http://acreditacion.mined.gob.sv/help.txt

Please You see this url above
I am explain step by step

thank you my friend by your time Ok I explain. I have two file. So I want to filter the textFileWithCodes and myKMLfile. So I get a output file. The main filter is this line <SimpleData name="CODIGO">XXXXX</SimpleData> where XXXXX can be in textFileWithCodes Please my my friend this is a kml file The. KML expected is a map en google earth to know roads and bringing food to shelters for due to tropical storm that has left thousands homeless this week
Please You see this url above
I am explain step by step

Last edited by pcoj33; 10-19-2011 at 05:02 PM..

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to write in other language in text/xml file by reading english text/xml file using C++?

Hello Team, I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file. Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Discussion started by: SA_Palani
2 Replies

2. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

How to filter out data file...?

Hi... I would like to filter out my data file....in two different way 1st way is like this, I will take one example..here... The script should ask like this. Enter min value in first column Enter max value in first column Enter min value in second column Enter max value in... (5 Replies)
Discussion started by: nex_asp
5 Replies

5. UNIX for Dummies Questions & Answers

Need to filter data from a file

Hi, I have a file with hundreds of records. There are four fields on each line, separated by semicolons. Name Height (meters) Country Continent (Africa,Asia,Europe,North America,Oceania,South America,The Poles) I need to Write the command to find display how many mountains appear... (1 Reply)
Discussion started by: erora
1 Replies

6. Shell Programming and Scripting

Filter a .kml file (xml) to remove unwanted entries

Ok, i have a .kml file that that i want to trim down and get rid of the rubbish from. its formatted like so: <Placemark> <name><!]></name> <description><!</b><br/>Frequency: <b>2437</b><br/>Timestamp: <b>1304892397000</b><br/>Date: <b>2011-05-08... (11 Replies)
Discussion started by: Phear46
11 Replies

7. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

8. UNIX for Dummies Questions & Answers

Using input file to filter data from another file

I have a data file: abc Text Text Text Unique Text 123 Text word Line Unique Text fgh Text data Line Unique Text 789 Text Text Line Unique Text 543 Text Text Data Unique Text and a filter file 123 789 I want to extract out from the data file the two records that contain the keys... (1 Reply)
Discussion started by: tumblez
1 Replies

9. Windows & DOS: Issues & Discussions

Filter data from text file

Hi All We have got a text file, which has data dumped from 60 tables. From these 60 tables of data we need data from 4 tables only. I tried assigning line numbers to filter out data, but it is not working as intended. below is the sample file ----Table1----- 3,dfs,43,df 4,sd,5,edd... (18 Replies)
Discussion started by: b_sri
18 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

Featured Tech Videos