I work for a company that offers webhosting and DNS services. We are trying to migrate everything over to new servers and we’ve often run into stale zonefiles on our servers as customers have changed their authoritative servers to someone else.
I am trying to write a script that will check whois, ns, and SOA information to determine if a domain still uses us as an authoritative server.
I am attempting to use sed to filter the output of the following to display only the nameserver without the trailing “.”:
dig +noall +answer soa yahoo.com | sed 's/.*SOA\s*//' | sed 's/\.$//'
I’ve searched the net, but most sed command examples work on “lines” instead of “Words”.
The desired output would be as follows:
$ dig +noall +answer soa yahoo.com | sed '<Some SED code here>'
ns1.yahoo.com
Any suggestions would be helpful.
Rather than using removing the part that you don’t want, I would suggest using a bracketed subexpression to identify the bit that you do want, as follows:
dig +noall +answer soa yahoo.com | sed 's/.*SOA\s*//' | sed 's/^\([^ ]*\). .*/\1/g'This searches for a string beginning with some non-space characters, followed by a dot, a space, and then the rest of the line. It replaces that pattern with just the bit before the dot (which is subexpression #1).