If I have an input file with a list of users and their dates they were last signed in, how can I select with a sort | awk function the last minute lines?The dates are written in a +%H:%M:%S format.Example:George 12:00:15 Max    12:01:03 Kate   10:32:54 Adam   08:21:47 Andrea 12:00:10Current date is 12:01:04Outcomes of an if function would be 1st, 2nd and 5th lines
Get the last minute dated lines from list
bash;shell;awk;date;sort
In bash and using GNU date (default on most Linux systems), you can do this:threshold=$(( $(date -d 12:01:04 +%s) - 60 ))paste file <(awk '{ print $2 }' file | date -f - +%s) |  awk '$3 > '$threshold' { print $1,$2 }'Or to preserve formatting as per the example in the question:threshold=$(( $(date -d 12:01:04 +%s) - 60 ))paste file <(awk '{ print $2 }' file | date -f - +%s) |  awk '$3 > '$threshold |  cut -c 1-15Output:George 12:00:15Max    12:01:03Andrea 12:00:10For a real example you can also make the date '1 minute ago' (as per Gnouc's answer). The first line would be:threshold=$(date -d '1 minute ago' +%s)