Score:0

awk to process multiple lines and return several strings

cn flag

I have these strings:

  Certificate Name: domain1.com
    Serial Number: 37aadb8fae7b908e1228c3e71
    Domains: domain1.com www.domain1.com
    Expiry Date: 2022-11-20 02:14:29+00:00 (VALID: 3 days)
    Certificate Path: /etc/letsencrypt/live/domain1.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/domain1.com/privkey.pem
  Certificate Name: www.domain2
    Serial Number: 37aadb8fae7b908e1228c3e72
    Domains: www.domain2
    Expiry Date: 2021-10-19 02:15:45+00:00 (INVALID: EXPIRED)
    Certificate Path: /etc/letsencrypt/live/www.domain2/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/www.domain2/privkey.pem
  Certificate Name: domain3.com
    Serial Number: 37aadb8fae7b908e1228c3e73
    Domains: domain3.com www.domain3.com
    Expiry Date: 2022-12-17 02:11:37+00:00 (VALID: 30 days)
    Certificate Path: /etc/letsencrypt/live/domain3.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/domain3.com/privkey.pem
  Certificate Name: domain4.com
    Serial Number: 37aadb8fae7b908e1228c3e74
    Domains: domain4.com www.domain4.com
    Expiry Date: 2022-12-10 02:08:54+00:00 (VALID: 23 days)
    Certificate Path: /etc/letsencrypt/live/domain4.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/domain4.com/privkey.pem
  Certificate Name: domain5.com
    Serial Number: 37aadb8fae7b908e1228c3e75
    Domains: domain5.com www.domain5.com
    Expiry Date: 2022-11-20 02:14:37+00:00 (VALID: 3 days)
    Certificate Path: /etc/letsencrypt/live/domain5.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/domain5.com/privkey.pem
  Certificate Name: domain6.com
    Serial Number: 37aadb8fae7b908e1228c3e76
    Domains: domain6.com www.domain6.com
    Expiry Date: 2022-11-10 02:11:32+00:00 (INVALID: EXPIRED)
    Certificate Path: /etc/letsencrypt/live/domain6.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/domain6.com/privkey.pem
  Certificate Name: domain7.com
    Serial Number: 37aadb8fae7b908e1228c3e77
    Domains: domain7.com www.domain7.com
    Expiry Date: 2020-05-31 23:50:48+00:00 (INVALID: EXPIRED)
    Certificate Path: /etc/letsencrypt/live/domain7.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/domain7.com/privkey.pem
  Certificate Name: domain8.com
    Serial Number: 37aadb8fae7b908e1228c3e78
    Domains: domain8.com www.domain8.com
    Expiry Date: 2022-11-28 02:14:42+00:00 (VALID: 11 days)
    Certificate Path: /etc/letsencrypt/live/domain8.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/domain8.com/privkey.pem  

I'm used to using sed, but I know it will only process line by line.

I've been trying to use awk for a while, but since I'm not familiar with it, I'm still struggling. But, I'm also open to other suggestions.

I just want to look for the keyword INVALID: EXPIRED and then return the domain name at the next line, and finally, it should have this output:

www.domain2
domain6.com
domain7.com
Score:1
sb flag

This should do the trick I think:

awk '/INVALID: EXPIRED/{getline;split($0,line,"/");print line[5]}'
Budianto IP avatar
cn flag
Awesome, it works, thanks!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.