Another option is to be more specific about what you are grepping for. For example:
whois stackoverflow.com | grep -E '^[[:space:]]*(Registr(ar|ant|y)|Sponsoring).*: '
This extracts only lines that begin with optional white space before either 'Registrar', 'Registrant', 'Registry', or 'Sponsoring', followed by any number (zero or more) of any character, followed by a colon and a space.
(BTW, this uses grep -E
rather than the obsolete and deprecated egrep
. They do the same thing.)
Output:
Registrar: NAME.COM, INC.
Sponsoring Registrar IANA ID: 625
Registry Domain ID: 108907621_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.name.com
Registrar URL: http://www.name.com
Registrar Registration Expiration Date: 2016-12-26T19:18:07Z
Registrar: Name.com, Inc.
Registrar IANA ID: 625
Registry Registrant ID:
Registrant Name: Sysadmin Team
Registrant Organization: Stack Exchange, Inc.
Registrant Street: 110 William St , Floor 28
Registrant City: New York
Registrant State/Province: NY
Registrant Postal Code: 10038
Registrant Country: US
Registrant Phone: +1.2122328280
Registrant Email: [email protected]
Registry Admin ID:
Registry Tech ID:
Registrar Abuse Contact Email: [email protected]
Registrar Abuse Contact Phone: +1.1 7203101849
BTW, while testing any form of text processing (incl. regular expressions) on text from slow sources (like a database query or from a remote source like whois or a http server), it's useful to run the slow command once and redirect output to a file, then test against the file. When you have what you want, make sure it works the same with directly-piped (fresh) data.
e.g.
whois stackoverflow.com > so.txt
Other useful things to do with whois
output:
extract Domain block at beginning of whos (field lines begin with 4 spaces and end with a colon):
grep -Ei '^[[:blank:]]+.*:[[:blank:]]' so.txt
Output:
Domain Name: STACKOVERFLOW.COM
Registrar: NAME.COM, INC.
Sponsoring Registrar IANA ID: 625
Whois Server: whois.name.com
Referral URL: http://www.name.com
Name Server: CF-DNS01.STACKOVERFLOW.COM
Name Server: CF-DNS02.STACKOVERFLOW.COM
Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
Updated Date: 26-nov-2015
Creation Date: 26-dec-2003
Expiration Date: 26-dec-2016
extract Registrant block, beginning with `Domain Name' field and ending with 'Registrar Abuse Contact Phone' field:
sed -n -e '/^Domain Name:/,/^Registrar Abuse Contact Phone:/p' so.txt
both of the above together:
sed -n -e '/^Domain Name:/,/^Registrar Abuse Contact Phone:/p
/^[[:blank:]]+.*:[[:blank:]] /p'
Output from all of the above can easily be further processed with awk
or any other text-processing tool that can be made to use a colon (:
) character as field-separator.