Sort as per the Dates and Months
I am getting little bit difficult in sorting the date ranges which are in a field like
$cat date_file.txt Jan 10 Jan 23 Jan 7 Jan 1 Jan 31 Jan 30 Jan 2 Jan 5 Apr 3 Apr 12 Apr 20 Aug 22 How make a sort as per the Month and date , i mean result should be as per the month and date wise. If i go for the sort -M , i am not able to get the list as per date of the particular month. |
The qn is whether you want them sorted alphabetically then numerically, or properly by date as a human would see them ie Feb comes before Apr.
If the former, you'd start by adding a leading zero to the single digit dates. If the latter, you'll need a tool that actually understands dates eg MySQL or Perl would prob be able to handle that. Perl has many modules you can use eg http://search.cpan.org/~stbey/Date-C.../Date/Calc.pod |
I have no much idea about the perl and mysql but i know sed and awk . There is any possible way to do using sed and awk to sort the dates of various months .
|
Code:
$ echo "Jan 10 |
Thanks Tinkster
I got the utilization of the sort option especially -M for sort of Months. One more thing, this code( sort -k1M -k2g ) also work properly what the need of using the 1,1M and 2,2g in the previous code. Any way How could we sort the weekdays , Mean- Sun ,Mon , Tue....Sat. if any file containing . |
All times are GMT -5. The time now is 02:56 PM. |