Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I wonder if someone could tell me why these awks are not working, they should supply the registrar and the expiry date :

${AWK} -F: '/Registrar:/ && $0 != ""  { getline; REGISTRAR=substr($0,2,17) } END { print REGISTRAR }'

and

awk '/Expiry date:/ { print $3 }'``

this is a print out of the whois :

Domain name:
    kurtisbro.co.uk

Registrant:
    kurtis brown

Registrant type:
    UK Individual

Registrant's address:
    23 Cambria Mews
    NOTTINGHAM
    NG3 4GZ
    United Kingdom

Registrar:
    Heart Internet Ltd t/a eXtend [Tag = EXTEND]

Relevant dates:
    Registered on: 01-Mar-2012
    Expiry date:  01-Mar-2014
    Last updated:  23-Jun-2012

Registration status:
    Registered until expiry date.

Name servers:
    ns.mainnameserver.com
    ns2.mainnameserver.com

WHOIS lookup made at 17:38:12 07-Aug-2012

-- 
This WHOIS information is provided for free by Nominet UK the central registry
for .uk domain names. This information and the .uk WHOIS are:

Copyright Nominet UK 1996 - 2012.

You may not access the .uk WHOIS or use any data from it except as permitted
by the terms of use available in full at http://www.nominet.org.uk/whois, which
includes restrictions on: (A) use of the data for advertising, or its
repackaging, recompilation, redistribution or reuse (B) obscuring, removing 
or hiding any or all of this notice and (C) exceeding query rate or volume   
limits. The data is provided on an 'as-is' basis and may lag behind the
register. Access may be withdrawn or restricted at any time. 
share|improve this question
2  
What do you expect the output to be? Please edit that into your question. –  Nifle Aug 7 '12 at 16:42
    
@Nifle I have added the info requested –  Kurtis Bro Aug 7 '12 at 16:46

2 Answers 2

up vote 0 down vote accepted
for DOMAIN in newcastle.co.uk  guinness.co.uk  ;do
    echo "";
    echo $DOMAIN;
    whois $DOMAIN | awk -F: '/Registrar:/ && $0 != ""  { getline; REGISTRAR=$0 } END { print REGISTRAR }';
    whois $DOMAIN | awk -F: '/Expiry date:/ && $0 != ""  { EXPDATE=$0 } END { print EXPDATE }';
done

Output:

newcastle.co.uk
Corporation Service Company (UK) Limited [Tag = CSC-CORP-DOMAINS]
Expiry date: 30-Mar-2014

guinness.co.uk
Melbourne IT t/a Internet Names Worldwide [Tag = MELBOURNE-IT]
Expiry date: 06-Jan-2014

share|improve this answer
    
A single query and a single awk script would be more elegant. Check out @Peter O's answer. –  tripleee Jan 22 '13 at 11:09

The following examples extract both items, using custom Record Separators. They both handle multiple lines in the Registrar: record.


awk -vRS="(\n *Registrar:\n)|(\n +Expiry date: +)" \
'NR==2{ $0=gensub( /(^|\n) +/, "\\1","g" ) # gensub requires GNU awk
        match($0,/\n\n/); print substr($0,1,RSTART-1) } 
 NR==3{ match($0,/\n/);   print substr($0,1,RSTART-1) }'

or

awk -vRS="\n\n" '
 $1 == "Registrar:" { 
    gsub( /(^|\n) +/, "\n" )   # remove leading spaces
    sub( /Registrar:\n/, "" )  # remove "Registrar:" header line
    print 
 } 
 $1" "$2 == "Relevant dates:" { 
    match( $0, /Expiry date: +/ ); beg=RSTART+RLENGTH
    match( $0, /Expiry date: +[^\n]+/ )
    print substr( $0, beg , RSTART+RLENGTH-beg ) 
 }' 

output

Heart Internet Ltd t/a eXtend [Tag = EXTEND]
01-Mar-2014
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.