#!/usr/bin/awk -f
# gph2map.awk version 1 by Ben Collver
# Convert geomyidae to gophernicus gophermap
# usage: awk -f gph2map.awk index.gph >gophermap

BEGIN {
   FS = "\t"
}

/^\[/ {
   # trim leading and trailing square brackets
   sub(/^\[/, "")
   sub(/\]$/, "")

   # convert | to \t but convert escaped \| to |
   gsub(/\\\|/, "\v")
   gsub(/\|/, "\t")
   gsub(/\v/, "|")

   printf "%s%s\t%s\t%s\t%s\r\n", $1, $2, $3, $4, $5
   next
}

{
   printf "i%s\tErr\tnull.host\t1\r\n", $0
}