LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Grep. Driving myself Insane. (https://www.linuxquestions.org/questions/linux-newbie-8/grep-driving-myself-insane-4175593833/)

benjam1nrk 11-18-2016 10:02 PM

Grep. Driving myself Insane.
 
I am running a command that looks like this:
Code:

./ssl-cert-check.sh -s oc.mydomain.com -p 443
It produces this output:
Code:

Host                                            Status      Expires      Days
----------------------------------------------- ------------ ------------ ----
oc.mydomain.com:443                        Valid        Feb 16 2017  90

I want to extract the "Days" from the output, 90 in this instance.

I have been unsuccessful using the following bash command
Code:

./ssl-cert-check.sh -s oc.visionsxtreme.com -p 443|grep '/([0-9])+$/m'
This regex appears to work in the web regex testers, but I cannot produce the desired results in the shell. What am I doing wrong, besides driving myself crazy?!

Thank you. Ben

syg00 11-18-2016 10:18 PM

Over thinking it way too much - try "grep -oE '[0-9]+$' ".

benjam1nrk 11-18-2016 10:23 PM

Thank you, but running the following command still does not produce any output.
Code:

./ssl-cert-check.sh -s oc.mydomain.com -p 443|grep -oE '([0-9])+$'

syg00 11-18-2016 10:27 PM

The reason for things like that is generally whitespace at end of line - add it to your regex.

benjam1nrk 11-18-2016 10:58 PM

Thank you, I should have realized some white space may have existed. The following worked:
Code:

./ssl-cert-check.sh -s oc.mydomain.com -p 443|grep -oE '([0-9])+ *$'
I appreciate the help!

grail 11-19-2016 01:05 AM

A little longer, but this type of thing is well suited to awk:
Code:

./ssl-cert-check.sh -s oc.mydomain.com -p 443 | awk '/[0-9]/{print $NF}'


All times are GMT -5. The time now is 05:49 AM.