summaryrefslogtreecommitdiff
path: root/foaf/rdf2turtle.sh
blob: 676cd254b09475b475a7c569ef640c3fff2f33bc (plain)
  1. #!/bin/sh
  2. set -e
  3. rdffile="$1"
  4. ttlfile="${2:-$(basename "$rdffile" .rdf).ttl}"
  5. exit1() {
  6. echo "ERROR: $1"
  7. exit 1
  8. }
  9. [ -e "$rdffile" ] || exit1 "RDF file \"$rdffile\" does not exist."
  10. [ ! -e "$ttlfile" ] || exit1 "Turtle file \"$ttlfile\" already exists."
  11. base="$(perl -ne '/\bxml:base="(http.+)"/ and print $1 and exit;' "$rdffile")" || true #'
  12. rapper -i rdfxml ${base:+-O "$base"} -o turtle "$rdffile" > "$ttlfile"
  13. perl -i -pe 's/ {4}/\t/g' "$ttlfile"