Skip to content

Instantly share code, notes, and snippets.

@iMartyn
Created September 19, 2018 10:20
Show Gist options
  • Save iMartyn/25c75e19e9466cfd6f322b24e036f34b to your computer and use it in GitHub Desktop.
Save iMartyn/25c75e19e9466cfd6f322b24e036f34b to your computer and use it in GitHub Desktop.
awk and grep to convert dns zonefile to hosts file
#!/bin/bash
ZONEFILE=$1
grep 'ORIGIN\|A\W\+[0-9]\{1,3\}' $ZONEFILE | awk '{if ($1 == "$ORIGIN") {mydomain=$2} else if ($2 == "A") {print $3 " " mydomain} else {{print $4 " " $1 "." mydomain}}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment