I have a file contains the following data (only sample data is shown. the file will contain maximum 2001 lines)
0001:3002:2018/07/16:12.34.31:ERR
0002:3002:2018/07/16:12.34.44:ERR
0003:3002:2018/07/16:12.34.57:ERR
0004:3002:2018/07/16:12.35.10:ERR
0005:3002:2018/07/16:12.35.23:ERR
0006:3002:2018/07/16:12.35.36:ERR
0007:3002:2018/07/16:12.35.49:ERR
0008:3002:2018/07/16:12.36.02:ERR
0009:3002:2018/07/16:12.36.15:ERR
I'll be passing a date say 2018/07/16:12.36.15 to the bash script. I want to read each line from this file and compare the date in the line with the passed date and return the line whose date is greater than passed date.
What I have done so far?
#!/bin/sh
SEARCH_DATE=$1
errorCodeFilePath=/home/.errorfile.log
lines=`cat $errorCodeFilePath`
for line in $lines; do
errorCodeDate=$(echo $line |grep -Eo '[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}:[[:digit:]]{2}.[[:digit:]]{2}.[[:digit:]]{2}');
if [ $errorCodeDate -ge $SEARCH_DATE ];
then
echo $errorCodeDate
fi
done
Questions
I'm not sure if the date comparison will work? I'm getting "error integer expression expected". I literally have no idea how to write Bash scripts and this is my first try at all.
How to make this date comparison works? Also after the date comparison work I need to get the digits between first : and the second : for all the matching lines.