aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/osm/osm.osc.by_member
blob: 5f9d9be50267fd13655cd88dfcbe57c191f1324e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

while read -r line
do

    TYPE=$(echo $line | cut -d ' ' -f1) # field1 is type
    ID=$(echo $line | cut -d ' ' -f2)   # field2 is ID

    NEW_MEMBERS=$(echo $line |\
               cut -d' ' -f3- |\
               sed -r 's/([0-9]+)/<member type=\"relation\" ref=\"\1\" role=\"subarea\"\/>/g')

    echo $NEW_MEMBERS

    # print matched element with new tags to .osc file
    cat $1 |\
    sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ {
                 /<$TYPE id=\"$ID\"/ {
                     s/(version=\"[0-9]+\")(.*)/\1>/
                     a \ \ \ \ $NEW_MEMBERS
                 }
                 p
                 /<\/$TYPE/ q
            }" >> $1.osc
done

# Add .osc structure for output
sed -ir '1 i <osmChange version="0.6" generator="bash script">
         1 i <modify>
         $ a </modify>
         $ a </osmChange>' $1.osc