LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2015, 09:46 PM   #1
socalheel
Member
 
Registered: Oct 2012
Location: Raleigh, NC
Distribution: CentOS / RHEL
Posts: 158

Rep: Reputation: 3
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.

Last edited by socalheel; 04-28-2015 at 09:48 PM.
 
Old 04-28-2015, 11:40 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Code:
grep '.zip$' | sort | tail -n1
 
1 members found this post helpful.
Old 04-29-2015, 03:31 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
You may find GNU sort is much more accommodating than you think. Check the "-g" option.
 
1 members found this post helpful.
Old 04-29-2015, 05:52 AM   #4
socalheel
Member
 
Registered: Oct 2012
Location: Raleigh, NC
Distribution: CentOS / RHEL
Posts: 158

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by NevemTeve View Post
Code:
grep '.zip$' | sort | tail -n1
Quote:
Originally Posted by syg00 View Post
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!!!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed to sort files based on timestamp in bash scripting. maunir Programming 3 01-24-2011 01:46 PM
sort oldest 5 files in a directory tree recursively based on timestamp Linux abhelp Programming 1 06-04-2010 04:58 AM
will it be poosile to sort the output of ls command based on timestamp of files. shad.ithbti Linux - Newbie 1 09-15-2009 01:51 AM
find all files in current folder and all subfolders and sort all by timestamp dlnlinux Linux - Newbie 2 06-03-2008 11:29 AM
script to sort files according to timestamp aeby Linux - Newbie 1 05-16-2007 08:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration