Sort the records according to the date

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Sort the records according to the date

Rinkkzy
Hi.!!
how to sort the records according to the date of birth of employees ??
and here  i dont know the field position.
Reply | Threaded
Open this post in threaded view
|

Re: Sort the records according to the date

Guru
Administrator
Hi

  Please provide a sample input file which will give us some idea about file format and date format as well.

Guru.
Reply | Threaded
Open this post in threaded view
|

Re: Sort the records according to the date

Rinkkzy
This is a sample file and here the date format may be in any format.consider any one format

| Eid | Name   | DOB        |   Remark  
|  1   | Rinkal   | 1993/01/08 | abc    
|   2  | Kajal     | 1990/07/14 | xyz    
|   3  | Bhumi   | 1992/03/09 | dsfgd|
|   4  | Heena   | 1992/02/08 | asdf  
|   5  | Hina      | 1992/02/08 | Dept    
|   6  | Dimpal  | 1993/05/10 | Sales
|   7  | Vruti     | 1991/08/18 | Sales  
|   8  | Rinkle   | 1986/04/13 | Sales
|   9  | Hitesh   | 1987/03/29 | Sales
|  10 | Aarya    | 1992/09/06 | Sales
|  11 | Ramji    | 1991/09/11 | Sales
|  12 | Dipti     | 1985/01/16 | Sales
|  13 | Shweta | 1991/08/09 | Sales

Reply | Threaded
Open this post in threaded view
|

Re: Sort the records according to the date

Guru
Administrator
You can do it like this for the format which is present in the input file:

$ sort -t"|" -n -k 4.2,4.5 -k 4.7,4.8 -k 4.10,4.11  file
| Eid | Name   | DOB        |   Remark
|  12 | Dipti     | 1985/01/16 | Sales
|   8  | Rinkle   | 1986/04/13 | Sales
|   9  | Hitesh   | 1987/03/29 | Sales
|   2  | Kajal     | 1990/07/14 | xyz
|  13 | Shweta | 1991/08/09 | Sales
|   7  | Vruti     | 1991/08/18 | Sales
|  11 | Ramji    | 1991/09/11 | Sales
|   4  | Heena   | 1992/02/08 | asdf
|   5  | Hina      | 1992/02/08 | Dept
|   3  | Bhumi   | 1992/03/09 | dsfgd|
|  10 | Aarya    | 1992/09/06 | Sales
|  1   | Rinkal   | 1993/01/08 | abc
|   6  | Dimpal  | 1993/05/10 | Sales


For more details on the sort command options, refer this article.

Guru.
Reply | Threaded
Open this post in threaded view
|

Re: Sort the records according to the date

Rinkkzy
But if i dont know that DOB is placed at which position..I only have the information that DOB field exist there.
suppose...the date format is yyyy/mm/dd or yyyy-mm-dd then,
Is there any way to find out theDOB field using "/" or "-" character and sort i...??
Reply | Threaded
Open this post in threaded view
|

Re: Sort the records according to the date

Guru
Administrator
Hi
   This looks like a "homework" question given in school/college. ???