I am using grep to extract the expiration date from a WHOIS record. The command line I use is:

whois -H domainname.com | grep -m 1 'Expir'

and I get what I need, i.e. the line with the first match containing 'Expir'. However, I would like to trim this output and get only the date, i.e. xxxx-xx-xx.

Currently, the output looks like this:

   Registry Expiry Date: 2018-01-23T16:07:52Z

There are extra characters after the date, delimited by the character T, as well as extra characters before the date. How can I eliminate all those and keep the date only?


$ whois -H google.com | grep -oP 'Expiry Date: \K.*(?=T)'
  • 1
    Perfect! Thanks a lot. I don't understand any of it, but it works :) – Tocell Nov 8 '17 at 5:27

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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