Subtract date in a loop

I have a file with name and date---

$ cat file.log
userA     01-06-2014
userB     25-05-2014
userC     16-05-2014
userC     01-03-2014

I want to search for the current date and get the name for that date. If current date is not found, go back 1 day and search and so on till it finds the user.
In this case, if I am searching for userC, i have to start from current date and go on till i hit 16-05-2014.

Please note, my search is based on date.

Thanks

Sort by date descending grep for your user and use head to get first:

$ sort -k2.8,2.11dr -k2.5,2.6dr -k2.2,2.3dr file.log | grep "^userC" | head -1
userC 16-05-2014
1 Like

Thanks...it works !!