#!/bin/bash

set +e

source "$(dirname $0)/00-config"
mkdir -p $WORKDATADIR/05
rm $WORKDATADIR/05/*

for i in working-data/04/*; do
  cat "$WORKDATADIR/02/$(basename $i .json)" |  sed -E "s/.*\"name\"=\"(.*)\"\]\[\"highway.*/\\1/" | sort > $WORKDATADIR/05/requested
  cat "$i" | jq -r ".elements[] | select(.type == \"way\") | .tags.name" | sort | uniq > $WORKDATADIR/05/returned
  comm "$WORKDATADIR/05/requested" "$WORKDATADIR/05/returned" -3 > "$WORKDATADIR/05/$(basename $i .json)"
  if [ ! -s "$WORKDATADIR/05/$(basename $i .json)" ]; then
    rm "$WORKDATADIR/05/$(basename $i .json)"
  fi
done
