Sort by First Date Field (MM/DD/YY)

Sort by First Date Field (MM/DD/YY)

Post by R » Sat, 05 Jul 2003 04:35:40



How do i sort the flat file given below. I want the file to be sorted
by the date. Any help, Please post the solution.  -TIA

11/13/02   8564528  A1 920316
09/13/02   95761826 A2 920316
12/10/02   9488073  A2 920316
08/11/02   102723151A2 920316
07/03/02   9659327  A1 920316
05/04/02   1120732  A2 920316
01/06/03   1165141  A1 920316
01/08/03   1167543  A1 920316
01/05/03   1165141  A1 920316
02/14/03   1167543  A1 920316
03/15/03   1165141  A1 920316
04/22/03   1167543  A1 920316

 
 
 

Sort by First Date Field (MM/DD/YY)

Post by Barry Margoli » Sat, 05 Jul 2003 05:43:18




>How do i sort the flat file given below. I want the file to be sorted
>by the date. Any help, Please post the solution.  -TIA

>11/13/02   8564528  A1 920316
>09/13/02   95761826 A2 920316
>12/10/02   9488073  A2 920316
>08/11/02   102723151A2 920316
>07/03/02   9659327  A1 920316
>05/04/02   1120732  A2 920316
>01/06/03   1165141  A1 920316
>01/08/03   1167543  A1 920316
>01/05/03   1165141  A1 920316
>02/14/03   1167543  A1 920316
>03/15/03   1165141  A1 920316
>04/22/03   1167543  A1 920316

sort -t/ -k 3,3n -k 1,1n -k 2,2n

--

Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Sort by First Date Field (MM/DD/YY)

Post by Heiner Steve » Sun, 06 Jul 2003 04:46:40




 >
 >>How do i sort the flat file given below. I want the file to be sorted
 >>by the date. Any help, Please post the solution.  -TIA
 >>
 >>11/13/02   8564528  A1 920316
 >>09/13/02   95761826 A2 920316
 >>12/10/02   9488073  A2 920316
 >>08/11/02   102723151A2 920316
 >>07/03/02   9659327  A1 920316
 >>05/04/02   1120732  A2 920316
 >>01/06/03   1165141  A1 920316
 >>01/08/03   1167543  A1 920316
 >>01/05/03   1165141  A1 920316
 >>02/14/03   1167543  A1 920316
 >>03/15/03   1165141  A1 920316
 >>04/22/03   1167543  A1 920316
 >
 > sort -t/ -k 3,3n -k 1,1n -k 2,2n

[this is slightly off-topic...]

The problem here arose because of the way dates were represented,
in the format MM/DD/YY, which is (as far as I know) only used
in the United States.

The international standard ISO 8601 describes another date format:

    YYYY-MM-DD

    [ http://www.cl.cam.ac.uk/~mgk25/iso-time.html ]

This format has the advantage, that dates are directly sortable.
The first lines from the log file above would have looked like this:

    2002-11-13   8564528  A1 920316
    2002-09-13   95761826 A2 920316
    2002-12-10   9488073  A2 920316
    2002-08-11   102723151A2 920316
    [...]

A simple "sort" on this file would have brought the lines
into chronological order.

Heiner
--
 ___ _

\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/

 
 
 

1. Changing all date fields from mm/dd/yy to dd/mm/yy

Please, I'm looking for a way to change all date fields in a specified
file, like this:

solaris> cat file

05/23/06      03/12/06

07/10/06                   11/12/06           09/20/06

      03/11/06

I need change all date field from mm/dd/yy to dd/mm/yy, like this:

solaris> ./script < cat file

23/05/06        12/03/06

10/07/06                 12/11/06             20/09/06

       11/03/06

Thanks !

2. problem with ftp client behind redhat 7.2 iptables firewall

3. sort MM/DD/YY in reverse chron order with -k...

4. passing file descriptors through stream pipes?

5. How to translate date in dd/mm/yy format

6. Free Scripts: Metertek Perl Script Archive

7. How to convert Posix date to YY/MM/DD ?

8. all messages the same date and time (fetchmail)

9. How to read file modification date (mm-dd-yy) in Korn

10. Files modified since yy/mm/dd hh:mm

11. How to convert Unix date to DD/MM/YYYY HH:MM:SS

12. HELP: C prog to get mm/dd/yy format

13. How to convert dd/mm/yy to unix epoch time?