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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter a .kml file (xml) to remove unwanted entries
# 8  
Old 05-10-2011
Code:
perl -p0e 's/<Placemark>\n[^\n]+\n[^\n]+WPA-PSK-TKIP.*?<\/Placemark>\n//sg' file

# 9  
Old 05-10-2011
Your shell script worked also ahamed, but i dont seem to be able to output the result to a txt file.

> file.kml returns an error
| gedit returns an empty page

Sorry im such a n00b. Im not really up on this sort of thing
# 10  
Old 05-10-2011
what is the error you got? paste it
It should be like this
Code:
./script "pattern" >> file.kml

regards,
Ahamed
# 11  
Old 05-11-2011
Code:
remove=BTHomeHub 
sed -ne '/<Placemark>/{N;s/\(.*\)\n\(.*'$remove'.*\)/x\n\2/};/x/,/<\/Placemark>/d;p' file >newfile1
or
sed -ne '/<Placemark>/{N;s/\(.*\)\n\(.*'$remove'.*\)/x\n\2/;};/x/,/<\/Placemark>/{;{/'$remove'/{;:x;;n;/<\/Placemark>/!bx;/<\/Placemark>/d;};}};p' file > newfile1

Code:
remove=WPA-PSK-TKIP
sed -ne '/<Placemark>/{N;N;s/\(.*\)\n.*\(.*'$remove'.*\)/x\n\2/};/x/,/<\/Placemark>/d;p' file >newfile2

regards
ygemici
# 12  
Old 05-19-2011
Quote:
Originally Posted by ahamed101
Not a one liner but does the job

Code:
#!/bin/bash
i=1;f=0
while read line
do
  if [ "$line" == "<Placemark>" ]; then s=0; fi
  echo "$line" | grep "$1" >/dev/null 2>&1
  if [ $? -eq 0 ] && [ $f -eq 0  ] ;then f=1;fi
  if [ "$line" == "</Placemark>" ]; then s=1; fi
  x[$i]="$line"
  if [ $s -eq 1 ];then
    if [ $f -eq 0 ];then
      for((j=1;j<=i;j++))
      do
        echo ${x[$j]}
      done
    fi
    i=0;unset x;f=0
  fi
  ((i=i+1))
done < infile

Usage : script pattern

regards,
Ahamed
Does anyone knows how can this be implemented using busybox. The first issue I had was with the for loop which I was able to fix with this and a counter j=j+1 in the loop:

Code:
while j <= i

Which I think will do the same but now this statement:

Code:
echo ${x[$j]}

Causes this error: Syntax error: Bad substitution.

I am not really sure how this script does it's magic so I am not really sure how to make it work with busybox with the same results; which is to eliminate the whole xml element if the string is found in this element .... <Movie>....</Movie> vs <Placemark> in my case.

Thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove unwanted commas from a .csv file?

how to remove unwanted commas from a .csv file Input file format "Server1","server-PRI-Windows","PRI-VC01","Microsoft Windows Server 2012, (64-bit)","Powered On","1,696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"... (5 Replies)
Discussion started by: ranjancom2000
5 Replies

2. Shell Programming and Scripting

Filter file to remove duplicate values in first column

Hello, I have a script that is generating a tab delimited output file. num Name PCA_A1 PCA_A2 PCA_A3 0 compound_00 -3.5054 -1.1207 -2.4372 1 compound_01 -2.2641 0.4287 -1.6120 3 compound_03 -1.3053 1.8495 ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

3. Shell Programming and Scripting

Removing unwanted tags from xml file

I have a XML file given as below: "<ProductUOMAlternativeDetails> <removetag> <UOMCode>EA</UOMCode> <numeratorForConversionToBaseUOM>1</numeratorForConversionToBaseUOM> <denominatorForConversionToBaseUOM>1</denominatorForConversionToBaseUOM> <length>0.59</length> <width>0.96</width> ... (3 Replies)
Discussion started by: vikingh
3 Replies

4. Shell Programming and Scripting

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 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

5. Shell Programming and Scripting

Filter/remove duplicate .dat file with certain criteria

I am a beginner in Unix. Though have been asked to write a script to filter(remove duplicates) data from a .dat file. File is very huge containig billions of records. contents of file looks like 30002157,40342424,OTC,mart_rec,100, ,0 30002157,40343369,OTC,mart_rec,95, ,0... (6 Replies)
Discussion started by: mukeshguliao
6 Replies

6. Shell Programming and Scripting

Remove unwanted lines

I have a .xml file, where i need some output. The xml file is like: Code: <?******?></ddddd><sssss>234</dfdffsdf><sdhjh>534</dfdfa>......... /Code I need the output like: code 234 534 . . . /code How can i do it? (5 Replies)
Discussion started by: anupdas
5 Replies

7. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

8. Shell Programming and Scripting

Remove unwanted XML Tags

I have set of sources and the respective resolution. Please advice how to resolve the same using Unix shell scripting. Source 1: ======= <ext:ContactInfo xmlns:ext="urn:AOL.FLOWS.Extensions"> <ext:InternetEmailAddress>AOL@AOL.COM</ext:InternetEmailAddress> </ext:ContactInfo> Resoultion... (1 Reply)
Discussion started by: ambals123
1 Replies

9. Shell Programming and Scripting

Filter unwanted lines

Hi All, I have the below input and i only want to filter out some un-wanted info from here. Expected output is below. Can somebody help ? The catch is that i want to grep those lines with term "k=" and lines with term "**" as the 1st column and "07" as the last column. And the number of... (15 Replies)
Discussion started by: Raynon
15 Replies

10. Shell Programming and Scripting

Remove unwanted data?

Hi Can any one help me remove the unwanted data? I would want to remove the complete event id 4910 ( the type there is INFO), that means, I have to remove starting from 7th - 19th lines. can any one of you please help? Thanks, (24 Replies)
Discussion started by: hitmansilentass
24 Replies
Login or Register to Ask a Question