I have a file containing timestamps from the date command, for
example:
Thu May 13 13:51:36 PDT 2010
Wed May 12 11:51:36 PDT 2010
Mon Fed 10 10:08:20 PDT 2009
How to get the oldest timestamp? If I use a different "date" command,
will it be easier to get the oldest timestamp?
Thanks.
|
|
0
|
|
|
|
Reply
|
junw2000 (221)
|
5/24/2010 11:21:12 PM |
|
On May 24, 4:21=A0pm, Jack <junw2000@gmail.com> wrote:
> I have a file containing timestamps from the date command, for
> example:
> Thu May 13 13:51:36 PDT 2010
> Wed May 12 11:51:36 PDT 2010
> Mon Fed 10 10:08:20 PDT 2009
>
> How to get the oldest timestamp? If I use a different "date" command,
> will it be easier to get the oldest timestamp?
$ TZ=3DGMT0 date +'%Y-%M-%dT%H:%M:%S'
2010-05-25T03:05:54
$ LC_ALL=3DC sort | head -1
|
|
0
|
|
|
|
Reply
|
Michael
|
5/25/2010 3:08:03 AM
|
|
Jack wrote:
> I have a file containing timestamps from the date command, for
> example:
> Thu May 13 13:51:36 PDT 2010
> Wed May 12 11:51:36 PDT 2010
> Mon Fed 10 10:08:20 PDT 2009
>
> How to get the oldest timestamp? If I use a different "date" command,
> will it be easier to get the oldest timestamp?
>
> Thanks.
You could use a complicated sort command. (untested)
sort -r -k6n,7 -k2M,3 -k3n,4 -k4.1n,4.3 -k4.4n,4.6 -k4.7n4.9 | head -1
Or you could save simpler time stamps with
date +%Y%m%d%H%M%S
Or with gnu date you could save 'epochtime' with
date +%s
With either of the last you could simply sort -n and pipe to tail -1
(or sort -rn and pipe to head -1).
|
|
0
|
|
|
|
Reply
|
Jon
|
5/25/2010 3:16:18 AM
|
|
On May 24, 8:16=A0pm, Jon LaBadie <jlaba...@aXcXm.org> wrote:
> Jack wrote:
> > I have a file containing timestamps from the date command, for
> > example:
> > Thu May 13 13:51:36 PDT 2010
> > Wed May 12 11:51:36 PDT 2010
> > Mon Fed 10 10:08:20 PDT 2009
>
> > How to get the oldest timestamp? If I use a different "date" command,
> > will it be easier to get the oldest timestamp?
>
> > Thanks.
>
> You could use a complicated sort command. (untested)
>
> sort -r -k6n,7 -k2M,3 -k3n,4 -k4.1n,4.3 -k4.4n,4.6 -k4.7n4.9 | head -1
>
> Or you could save simpler time stamps with
>
> =A0 =A0date +%Y%m%d%H%M%S
>
> Or with gnu date you could save 'epochtime' with
>
> =A0 =A0date +%s
>
> With either of the last you could simply sort -n and pipe to tail -1
> (or sort -rn and pipe to head -1).
If I have two timesamps obtained from " date +%Y%m%d%H%M%S ", how to
compare them to get the older timestamp?
Thanks.
|
|
0
|
|
|
|
Reply
|
Jack
|
5/25/2010 5:40:09 AM
|
|
Jack wrote:
> On May 24, 8:16 pm, Jon LaBadie <jlaba...@aXcXm.org> wrote:
>> Jack wrote:
>>> I have a file containing timestamps from the date command, for
>>> example:
>>> Thu May 13 13:51:36 PDT 2010
>>> Wed May 12 11:51:36 PDT 2010
>>> Mon Fed 10 10:08:20 PDT 2009
>>> How to get the oldest timestamp? If I use a different "date" command,
>>> will it be easier to get the oldest timestamp?
>>> Thanks.
>> You could use a complicated sort command. (untested)
>>
>> sort -r -k6n,7 -k2M,3 -k3n,4 -k4.1n,4.3 -k4.4n,4.6 -k4.7n4.9 | head -1
>>
>> Or you could save simpler time stamps with
>>
>> date +%Y%m%d%H%M%S
>>
>> Or with gnu date you could save 'epochtime' with
>>
>> date +%s
>>
>> With either of the last you could simply sort -n and pipe to tail -1
>> (or sort -rn and pipe to head -1).
>
> If I have two timesamps obtained from " date +%Y%m%d%H%M%S ", how to
> compare them to get the older timestamp?
Michael Paoli seems to have already answered what you're asking for.
Use tail -n 1 or head -n 1 if your file has the timestamps sorted
(ascending/descending), otherwise, if the timestamps in your file are
unsorted, just use sort on your file before you apply head (or tail).
If you have the timestamps not in a file as you said in your OP, but
rather in variables then use the shell's test operator to compare the
variables, (in the above case with ISO dates) like [ $t1 < $t2 ] ,
where variables t1 and t2 contain the timestamp values.
If neither fits, clarify in what way your timestamps are organized, or
explain your problems with the given proposals.
Janis
>
> Thanks.
|
|
0
|
|
|
|
Reply
|
Janis
|
5/25/2010 7:36:23 AM
|
|
On May 24, 10:40=A0pm, Jack <junw2000@gmail.com> wrote:
> On May 24, 8:16=A0pm, Jon LaBadie <jlaba...@aXcXm.org> wrote:
> > Jack wrote:
> > > I have a file containing timestamps from the date command, for
> > > example:
> > > Thu May 13 13:51:36 PDT 2010
> > > Wed May 12 11:51:36 PDT 2010
> > > Mon Fed 10 10:08:20 PDT 2009
> > > How to get the oldest timestamp? If I use a different "date" command,
> > > will it be easier to get the oldest timestamp?
> > You could use a complicated sort command. (untested)
> > sort -r -k6n,7 -k2M,3 -k3n,4 -k4.1n,4.3 -k4.4n,4.6 -k4.7n4.9 | head -1
> > Or you could save simpler time stamps with
> > =A0 =A0date +%Y%m%d%H%M%S
> If I have two timesamps obtained from " date +%Y%m%d%H%M%S ", how to
> compare them to get the older timestamp?
That:
$ date +%Y%m%d%H%M%S
won't always work.
Hints: timezones, daylight saving time / summer time
Hence, on
news:04e6a7df-4342-4596-bf0c-c8d1e8367ecd@y6g2000pra.googlegroups.com
I suggested:
> $ TZ=3DGMT0 date +'%Y-%M-%dT%H:%M:%S'
> 2010-05-25T03:05:54
> $ LC_ALL=3DC sort | head -1
As that date command as shown will work and sort (as shown)
consistently, as long as one's system times are correct, or at least
consistent.
|
|
0
|
|
|
|
Reply
|
Michael
|
5/29/2010 1:13:34 PM
|
|
|
5 Replies
611 Views
(page loaded in 0.092 seconds)
Similiar Articles: how to get microsecond file timestamps - comp.unix.solaris ...I believe in Solaris UFS file timestamps are in microseconds. How can userland code get the microsecond data? ... schily.blogspot.com/ URL: http://cdrecord.berlios.de/old ... How to read TIMESTAMP field in UTC? - comp.databases.mysql ...How can I get the timestamp in UTC, without conversion? UTC_TIMESTAMP() returns the ... timestamp values: -- near the start of the dump file /*!40103 SET @OLD ... create file with timestamp 6 hours back - comp.unix.solaris ...... file using the touch command with -t, so that the file is 6 hours old (the 6 ... get file timestamp - comp.unix.programmer create file with timestamp 6 hours back - comp.unix ... get file timestamp - comp.unix.programmerAnyway to grab a file's timestamp (date, time, seconds) using straight Unix Shell commands or ksh bultin? (not GNU, not perl, not C) ... TimeStamp - comp.protocols.time.ntpI've successfully set up my NTP server: an old 850MHz P3 box running FreeBSD ... but a SELECT returns them adjusted to the server's time zone. How can I get the timestamp in ... chmod and file timestamp - comp.unix.solarisget file timestamp - comp.unix.programmer chmod and file timestamp - comp.unix.solaris get file timestamp - comp.unix.programmer chmod and file timestamp - comp.unix ... how to install depote file - comp.sys.hp.hpuxhow to get microsecond file timestamps - comp.unix.solaris ... how to install depote file - comp.sys.hp.hpux how to get microsecond file timestamps - comp.unix.solaris ... CreateFile() create time - comp.os.ms-windows.programmer.win32 ...... fn>...,CREATE_NEW..) sets the file creation time to the old creation ... how to get microsecond file timestamps - comp.unix.solaris ... CreateFile() create time - comp.os.ms ... bash timestamp command history - comp.unix.solarisfind command to skip directory - comp.unix.admin find and chmod - comp.unix.solaris get file timestamp - comp.unix.programmer find command to skip ... to remove a nonempty ... Timestamp Conversion - comp.protocols.time.ntpTIMESTAMP fields are stored in UTC, but a SELECT returns them adjusted to the server's time zone. How can I get the timestamp in UTC, without conversion? how to get the oldest timestamp record in an array list (Beginning ...Hi, I have an arraylist. now i want to get the record with the oldest timestamp from all the records present in the arraylist. example: arraylist[] re selecting the oldest record by timestamp: oldest, timestamp ...Hi, I am using DB2 database.I selected the TOPIC AREA as Mysql since I did not find that specific topic. I want to get the oldest password for that ... 7/24/2012 7:10:59 AM
|