Sponsored Content
Top Forums Shell Programming and Scripting Sorting dates in chronological order Post 302538981 by durden_tyler on Thursday 14th of July 2011 05:56:55 PM
Old 07-14-2011
Assuming that the dates in the 2nd column do not repeat in the file, you could do something like this in Perl -

Code:
$
$ # show the content of the data file "f7"
$
$ cat -n f7
     1  H|20-May-2011|MF_FF.dat|77164|731374590.96|1|1|731374590.96|76586|77164|578|2988|Y
     2  H|21-Jul-2011|MF_FF.dat|77178|731374590.96|2|4|731374590.96|76600|77178|578|3002|Y
     3  H|21-May-2011|MF_FF.dat|77178|731374590.96|2|4|731374590.96|76600|77178|578|3002|Y
     4  H|22-Aug-2011|MF_FF.dat|77195|731374590.96|3|4|731374590.96|76617|77195|578|3019|Y
     5  H|22-May-2011|MF_FF.dat|77195|731374590.96|3|4|731374590.96|76617|77195|578|3019|Y
     6  H|26-Mar-2011|MF_FF.dat|76444|713606875.00|1|1|713606875.00|75822|76444|622|3310|Y
     7  H|31-Oct-2009|MF_FF.dat|76444|713606875.00|1|1|713606875.00|75822|76444|622|3310|Y
     8  H|07-Dec-2010|MF_FF.dat|76444|713606875.00|1|1|713606875.00|75822|76444|622|3310|Y
$
$ # run the Perl program on the data file "f7"
$
$ perl -F"\|" -lane 'BEGIN {%x = qw(Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06
                                   Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12)}
                    ($d,$m,$y) = unpack("A2xA3xA4", $F[1]);
                    $data{$y.$x{$m}.$d} = $_;
                    END {foreach $k (sort keys %data) {print $data{$k}}}
                   ' f7
H|31-Oct-2009|MF_FF.dat|76444|713606875.00|1|1|713606875.00|75822|76444|622|3310|Y
H|07-Dec-2010|MF_FF.dat|76444|713606875.00|1|1|713606875.00|75822|76444|622|3310|Y
H|26-Mar-2011|MF_FF.dat|76444|713606875.00|1|1|713606875.00|75822|76444|622|3310|Y
H|20-May-2011|MF_FF.dat|77164|731374590.96|1|1|731374590.96|76586|77164|578|2988|Y
H|21-May-2011|MF_FF.dat|77178|731374590.96|2|4|731374590.96|76600|77178|578|3002|Y
H|22-May-2011|MF_FF.dat|77195|731374590.96|3|4|731374590.96|76617|77195|578|3019|Y
H|21-Jul-2011|MF_FF.dat|77178|731374590.96|2|4|731374590.96|76600|77178|578|3002|Y
H|22-Aug-2011|MF_FF.dat|77195|731374590.96|3|4|731374590.96|76617|77195|578|3019|Y
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Sorting filenames by order in another file

I would like to arrange /sort filenames ending with suffix like ".00XXXX". where X is a digit. However the order of arrangement is in a text file and is 'harpharzard'. e.g the text file may be like 002345 009807 001145 I wanted to avoid doing this using sql and exporting the text file back to... (4 Replies)
Discussion started by: samudimu
4 Replies

2. UNIX for Dummies Questions & Answers

Order sorting

How do you sort text in order using sed? :confused: For example 01 B D A C to 01 ABCD (3 Replies)
Discussion started by: evoGage
3 Replies

3. UNIX for Advanced & Expert Users

Uploading files in chronological order

Thanks for your help. (3 Replies)
Discussion started by: circuit.muni
3 Replies

4. Shell Programming and Scripting

multiple sorting with different order

Hi Guys, I have data like this HOS05 23/12/2008 10AM HOS06 15/12/2008 2PM HOS62 29/12/2008 10AM HOS64 23/12/2008 2PM HOS70 26/12/2008 10AM ZFT01 06/12/2008 10AM HOS73 11/12/2008 2PM MHOS0 05/12/2008 10AM MHOS0 20/12/2008 2PM MHOS0 27/12/2010 2PM MHOS0 11/12/2008 10AM MHOS0 30/12/2009... (1 Reply)
Discussion started by: ckarunprakash
1 Replies

5. UNIX for Dummies Questions & Answers

sorting PID in decreasing order using ps?

I am trying to sort the output in decreasing order of the process ID while using the ps command. I am having trouble doing this using the --sort part of ps. Also I was wondering if anyone knows what the "S" stands for under the process's status code? (3 Replies)
Discussion started by: crimputt
3 Replies

6. Shell Programming and Scripting

Sorting dates in Perl

I have a directory of backup files. named like this: ldap.data.04-06-2012.tar ldap.data.03-06-2012.tar ldap.data.02-06-2012.tar ldap.data.01-06-2012.tar ldap.data.31-05-2012.tar ldap.data.30-05-2012.tar ldap.data.29-05-2012.tar ldap.data.28-05-2012.tar ldap.data.27-05-2012.tar... (6 Replies)
Discussion started by: robsonde
6 Replies

7. UNIX for Dummies Questions & Answers

Any way to get find command o/p in chronological order?

Hi friends, I am using below script to gzip files after naming them in a particular order. but I intend to name them in numerical order as per their timings(earlier updated fle with a smaller numeric extension than later updated),but this script is not working as planned. please help with... (7 Replies)
Discussion started by: Jcpratap
7 Replies

8. UNIX for Dummies Questions & Answers

sorting sequences in ascending order

Hi, I have this single file with a number of sequence inside it of format >string1 data >string100 data >string10 ..... >string5 ... >string67 ...... the dots represent data. I wanted to get the sequences arranged in ascending order like >string1 data >string5 (5 Replies)
Discussion started by: sonia102
5 Replies

9. Shell Programming and Scripting

Sorting strings in reverse order

Hello, I have a large database of words and would like them sorted in reverse order i.e. from the end up. An example will make this clear: I have tried to write a program in Perl which basically takes the string from the end and tries to sort from that end but it does not seem... (5 Replies)
Discussion started by: gimley
5 Replies

10. UNIX for Beginners Questions & Answers

Sort in chronological order

I am trying to sort a log file in chronological order to identify which ones did not process and still have an old (probably yesterday's) date. This is a sample of the file:flatf 010140 flatf Thu May 10 22:22:11 CST 2018 flats finished flatf 010142 flatf Thu May 10 22:31:25 CST 2018 flats... (4 Replies)
Discussion started by: wbport
4 Replies
SLAPO-VALSORT(5)						File Formats Manual						  SLAPO-VALSORT(5)

NAME
slapo-valsort - Value Sorting overlay to slapd SYNOPSIS
/etc/openldap/slapd.conf DESCRIPTION
The Value Sorting overlay can be used with a backend database to sort the values of specific multi-valued attributes within a subtree. The sorting occurs whenever the attributes are returned in a search response. Sorting can be specified in ascending or descending order, using either numeric or alphanumeric sort methods. Additionally, a "weighted" sort can be specified, which uses a numeric weight prepended to the attribute values. The weighted sort is always performed in ascending order, but may be combined with the other methods for values that all have equal weights. The weight is specified by prepending an integer weight {<weight>} in front of each value of the attribute for which weighted sorting is desired. This weighting factor is stripped off and never returned in search results. CONFIGURATION
These slapd.conf options apply to the Value Sorting overlay. They should appear after the overlay directive. valsort-attr <attribute> <baseDN> (<sort-method> | weighted [<sort-method>]) Configure a sorting method for the specified attribute in the subtree rooted at baseDN. The sort-method may be one of alpha-ascend, alpha-descend, numeric-ascend, or numeric-descend. If the special weighted method is specified, a secondary sort-method may also be specified. It is an error to specify an alphanumeric sort-method for an attribute with Integer or NumericString syntax, and it is an error to specify a numeric sort-method for an attribute with a syntax other than Integer or NumericString. EXAMPLES
database bdb suffix dc=example,dc=com ... overlay valsort valsort-attr member ou=groups,dc=example,dc=com alpha-ascend FILES
/etc/openldap/slapd.conf default slapd configuration file SEE ALSO
slapd.conf(5), slapd-config(5). ACKNOWLEDGEMENTS
This module was written in 2005 by Howard Chu of Symas Corporation. The work was sponsored by Stanford University. OpenLDAP 2.4.21 2009/12/20 SLAPO-VALSORT(5)
All times are GMT -4. The time now is 10:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy