I have got the commands to pick up the date from a line comparing them with current date, I am looking to print another field from same line in if-then
statement.
cat /tmp/OutPrint |cut -d' ' -f 2 | while IFS= read line; do
now=$(date | cut -d' ' -f 4)
time_now=$(date -u -d "$now" +"%s") #seconds
time_line=$(date -u -d "$line" +"%s") #seconds
difference=$(echo $((time_now - time_line)))
if [ $difference -ge 2592000 ]
then
echo "Time difference is greater than 30 days"
else
echo "Time difference is less than 30 days"
fi
done
Below is the content of my file from which I am comparing the date with the current date. If the difference is more than 30 days I need the first field to be printed in the then
statement.
How can I print the first field in the then
statement ?
Input:
anhtdg5 03-Jul-2019
kjushr7 04-Aug-2020
bhyusj3 09-Mar-2017
losyej9 09-Mar-2017
nhtgsy57 09-Mar-2017
bpolise3 09-Mar-2017
uioshye2 14-Mar-2018
zsethfyu 23-Nov-2018
cnhysge 23-Mar-2018