Operating System - HP-UX
1754021 Members
7197 Online
108811 Solutions
New Discussion юеВ

Re: How can i order a file by date ..

 
SOLVED
Go to solution
Manuales
Super Advisor

How can i order a file by date ..

i have a file like this one (3500 rows apox):
user1 group1 Apr 12 2008 /home/user1.txt
user1 group3 May 18 2007 /home/user1.txt
user2 group5 Jan 23 2006 /home/user1.txt
user1 group1 Apr 12 2009 /home/user1.txt
user5 group6 Aug 17 2006 /home/user1.txt
user1 group3 Jul 16 2008 /home/user1.txt
user1 group8 Feb 15 14:13 /home/user1.txt
user5 group5 Jan 16 12:13 /home/user1.txt
user3 group1 Apr 15 2009 /home/user1.txt
user1 group8 Apr 13 2008 /home/user1.txt
......
......
......
......
......

i need to order these lines by date?
how can i do that?
do i have to make a program?
do you know something quick to do it?

thanks in advance.



P.S.This thread has been moved from HP-UX>System Administration to HP-UX > languages-HP Forums Moderator

12 REPLIES 12
Robert-Jan Goossens
Honored Contributor
Solution

Re: How can i order a file by date ..

Hi,

# ls -lr

Regards,
Robert-Jan
James R. Ferguson
Acclaimed Contributor

Re: How can i order a file by date ..

Hi:

If you didn't have mixed timestamp information with HH:MM and YYYY, then you could simply sort your file like this:

# sort -k5n,5 -kM3,3 -k4n,4 file

Since file timestamps that are within 6-months of the current date are reported with the HH:MM in place of the YYYY, you need to do something to manufacture the correct YYYY value as a sort key and/or generate a sort key that is an epoch seconds in the first place, and sort that.

Regards!

...JRF...
OldSchool
Honored Contributor

Re: How can i order a file by date ..

# sort -k5n,5 -kM3,3 -k4n,4 file

the month sort above appears to be incorrect. I believe it should read:

sort -k5n,5 -k3M,3 -k4n,4
James R. Ferguson
Acclaimed Contributor

Re: How can i order a file by date ..

Hi (again):

> OldSchool: the month sort above appears to be incorrect. I believe it should read: sort -k5n,5 -k3M,3 -k4n,4

Yes, I transposed the "M". Thanks.

Regards!

...JRF...
Tingli
Esteemed Contributor

Re: How can i order a file by date ..

Easiest way is:

ls -rlt
OldSchool
Honored Contributor

Re: How can i order a file by date ..

"Easiest way is:

ls -rlt" -and-

"# ls -lr"

the problem is she's asking about the contents of a file, as indicated by ..."i have a file like this one (3500 rows apox)...:

given the existing contents, its pretty much a "sort" issue
Jupinder Bedi
Respected Contributor

Re: How can i order a file by date ..

sort -k5n,5 -k3M,3 -k4n,4


and ls -lr


good luck
All things excellent are as difficult as they are rare
Steven Schweda
Honored Contributor

Re: How can i order a file by date ..

> and ls -lr

Did that posting contribute anything (other
than repeating an error)?

> i need to order these lines by date?

Even if the desire were to sort an "ls"
report, how would "-lr" use the date?
James R. Ferguson
Acclaimed Contributor

Re: How can i order a file by date ..

Hi:

> Jupinder: sort -k5n,5 -k3M,3 -k4n,4

...which adds what given that this is what I posted *yesterday*?

...JRF...