Compare date via shell script -


i have text:

aaaaaaaaaaaaaaaaaaaaddddd sadasdafnsdfoisjhpfnsf dasnfdfmsdf until: thu apr 29 19:41:02 eest 2021 dasd asdasmda[mfiun[hg[sm df, dfmsdf[ismdfsdfsd,flsdfsdf****************** 

i have parse date text , after have compare today , if greater otherwise have else , have write in shell script not well. can give me example how it.

thanks in advance.

i in 2 steps. (it done in one):

1, date string 2, comparison

e.g.:

 kent$  d=$(echo "aaaaaaaaaaaaaaaaaaaaddddd sadasdafnsdfoisjhpfnsf dasnfdfmsdf until: thu apr 29 19:41:02 eest 2021 dasd asdasmda[mfiun[hg[sm df, dfmsdf[ismdfsdfsd,flsdfsdf******************"|grep -o '[a-z].*[0-9]') 

check var d:

kent$  echo $d thu apr 29 19:41:02 eest 2021 

now compare date today. need convert both dates seconds comparison:

kent$  echo $(($(date -d"${d}" +%s)-$(date +%s))) 251171977 

i printed result of above command out. in case, assign var. or check result directly. if >0 means date in text in future. otherwise, in past(or same today).

edit

some math:

with int:

kent$  echo $((251171977/(3600*24))) 2907 

with precision:

kent$  echo "scale=2;251171977/(3600*24)"|bc  2907.08 

more precisely:

kent$  echo "scale=7;251171977/(3600*24)"|bc                                                                                                                                 2907.0830671 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -