I'm working on a script that will separate the Registrar information from a domains whois. So far it's working enough but there are a few things that I want to remove in order for it to be a bit cleaner. It works on the majority of domains. Here's my code:#!/bin/bashreg=$(whois stackoverflow.com | egrep -i 'Registrar|Sponsoring Registrar|Registrant|!internic')printf Below is my best attempt at finding the Registrar info:\nprintf $reg\nAnd here's what it outputs: Below is my best attempt at finding the Registrar info:with many different competing registrars. Go to http://www.internic.net   Registrar: NAME.COM, INC.   Sponsoring Registrar IANA ID: 625registrar's sponsorship of the domain name registration in the registry isdate of the domain name registrant's agreement with the sponsoringregistrar.  Users may consult the sponsoring registrar's Whois database toview the registrar's reported date of expiration for this registration.Registrars.I added some psudo-code in my grep to try and exclude the string internnic, in order to snip off that first line. I'd also want to find a way to remove the secondary registrar's sponsorship... etc.Is it possible to detect a string and not include that line? Thanks
How can I add a filter to my grep script to NOT include a string?
bash;scripting;grep;string;whois
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: 625Registry 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: sysadmin-team@stackoverflow.com Registry Admin ID:  Registry Tech ID:  Registrar Abuse Contact Email: abuse@name.com 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.txtOther 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.txtOutput:   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-2016extract 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.txtboth 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.