Currently I have file with structure asFoo Sign: blah    SubFoo Sign: blah    BarDate: 2017-11-31Foo Sign: blah    BarDate: NeverFoo Sign: blah    BarDate: 2016-12-20Foo Sign: blah    BarDate: 2014-12-20.... and so onThis are the main four categories of data which resides in the file. Don't go with the foo,bar,blah things, those are not important. Main important thing is BarDate and its value. Main PartCase 1: If BarDate value is Never I don't have to do anything.Case 2: If BarDate has some value other than Never it has the format as YYYY-MM-DD.Requirement: If the BarDate is within the span of 10 days from today it will mail to someone with it's details.So, today is 15-12-2015 if there is any BarDate which is within 15th to 25th December of 2015 a mail will be send with it's Foo Sign,BarDate.So a mail will be triggered for 2015-12-16,2015-12-24,2015-12-25...But not for 2014-12-16,2016-12-24,2015-12-26So far my shell script isfoo=bardate=outputfile=test.txtresult=newline=\n### just a workaround step ###if [ -f $outputfile ];then  `rm $outputfile`fi### filtering the date which doesn't have BarDate as Never, and writing it to a file ###`cat datafile | grep -e Foo Sign -e BarDate | grep -v Never | uniq >> $outputfile`IFS=$'\n'### contains is a custom function which returns 1 if param1 is substring of param2 ###for line in ${cat outputfile};  do    contains $line Foo Sign && foo=$line    ### constructing the result string ###    ### -----> here I have to extract the date and see if it resides within 10 days span from today <----- ###    ### then only the result string will be constructed ###    contains $line BarDate && bardate=$line && result=$result$newline$foo$newline$bardate$newline  done### mail the result ###echo -e $result | mailx -s BLAH someone@example.com
How to extract date and calculate if it is within x days from today?
bash;shell script;date;string;mailx
You can get current epoch time with date  +%sYou can also convert any time format to epoch time:date -d ${MY_TIME} +%sAnd these epoch times you can substract.Having the line with BarDate: 2017-11-31 in a variable LINE, you can extract the date using:MY_TIME=$(echo $LINE | cut -d: -f2)