LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sort based on timestamp? (https://www.linuxquestions.org/questions/programming-9/sort-based-on-timestamp-4175541064/)

socalheel 04-28-2015 09:46 PM

sort based on timestamp?
 
i have the following output from an aws s3cmd list command

Code:

2015-04-29 02:11        0  filename1.jpg
2015-04-28 21:11 104048385  filename2.zip
2015-04-29 02:11        0  filename3.txt
2015-04-29 02:09  2431494  filename4.zip
2015-04-29 02:11        0  filename5.jpg

i need to only retrieve the newest file with a .zip extension (this case it's filename4.zip). i simply am stumped ... any help or ideas where i can start to solve this one?

edit: in addition to the year, month, day, i also need to take into account the hours, minutes, and seconds.

NevemTeve 04-28-2015 11:40 PM

Code:

grep '.zip$' | sort | tail -n1

syg00 04-29-2015 03:31 AM

You may find GNU sort is much more accommodating than you think. Check the "-g" option.

socalheel 04-29-2015 05:52 AM

Quote:

Originally Posted by NevemTeve (Post 5354844)
Code:

grep '.zip$' | sort | tail -n1

Quote:

Originally Posted by syg00 (Post 5354935)
You may find GNU sort is much more accommodating than you think. Check the "-g" option.

omg that is so dang simple! i was thinking i was going to have to pass through the current date and time, calculate which file was closest to that date.

if i had a dollar for every time i was stumped by the simple things ...

thanks to you both!!!!!


All times are GMT -5. The time now is 03:36 PM.