Skip to content

Instantly share code, notes, and snippets.

@leite
Created November 23, 2015 02:38
Show Gist options
  • Save leite/14f66cf7c19f5946da51 to your computer and use it in GitHub Desktop.
Save leite/14f66cf7c19f5946da51 to your computer and use it in GitHub Desktop.
find equal ref (from, to) in members of relation
#!/bin/bash
#
# find equal ref (from, to) in members of relation
#
# @author leite <[email protected]>
# @license GPL version 3
#
relation=0
id=0
from=0
to=0
while IFS='' read -r line || [[ -n "$line" ]]; do
relation=$([[ $line == *"<relation "* ]] && echo 1 || echo $relation)
if [[ $line == *"<relation "* ]]; then
relation=1
id=$(echo $line | sed -rn "s/.* id='([^']+)'.*/\1/ p")
fi
if [[ $relation -eq 1 ]]; then
echo $line | grep " role='from'" >/dev/null && \
from=$(echo $line | sed -rn "s/.* ref='([^']+)' role='from'.*/\1/ p")
echo $line | grep " role='to'" >/dev/null && \
to=$(echo $line | sed -rn "s/.* ref='([^']+)' role='to'.*/\1/ p")
fi
if [[ $line == *"</relation>"* ]]; then
[[ $from -eq $to ]] && echo "relation ${id} duplicated!"
relation=0
fi
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment