Sponsored Content
Full Discussion: Sorting a date coulumn
Top Forums Shell Programming and Scripting Sorting a date coulumn Post 302117579 by rinku11 on Tuesday 15th of May 2007 11:54:04 AM
Old 05-15-2007
Sorting a date coulumn

Hi All,

I have a file say abc.txt with the below data.

1234 876S 01Mar2007 foo
1244 65DF 19Jan2007 boo
9924 234K 01Jan2006 koo
8866 8FGH 12Feb1999 roo
7777 ASDF 13May2007 soo


I need this file to be in sorted order depending on the date field.

e.g

8866 8FGH 12Feb1999 roo
9924 234K 01Jan2006 koo
1244 65DF 19Jan2007 boo
1234 876S 01Mar2007 foo
7777 ASDF 13May2007 soo

Any help is appreciated.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sorting on date

I have a file where dates in the form mm/dd/yyyy is the first field. How do I sort the file by the date field? Thanks, Duckman (6 Replies)
Discussion started by: Duckman
6 Replies

2. UNIX for Dummies Questions & Answers

date sorting

Hi at all, I have to sort a log file on timestamp field. That's field is the third! a log file sample..... 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:23|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:16|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:20|0.3.8... (3 Replies)
Discussion started by: nmilella
3 Replies

3. Shell Programming and Scripting

Date Sorting

Hi, I have a list of files that take on the format ABCDE_yymmdd and wish to sort them in ascending date order. I can't use the unix time stamp for the file as this could possibly be different from the date given in the file name. Does anyone know of any way this can be done using unix shell... (14 Replies)
Discussion started by: LiquidChild
14 Replies

4. UNIX for Dummies Questions & Answers

Sorting by date and time

Hi guys... I've been trying to do this for ages. Maybe you can help. I have log files like the examples below and I have grepped out certain lines from the files so that I can get an idea of who is logging on and how. So now I have the information in a new file but it is now in a different order... (7 Replies)
Discussion started by: padmundo
7 Replies

5. Shell Programming and Scripting

Date and Time sorting

Hi Guys! i have a problem of sorting column chronologically because the data i have in column is in the following format 06/Dec/2006:18:09:54 and need to be sorted in the following way (upto seconds) 06/Dec/2005:18:09:50 06/Dec/2005:18:09:51 31/Mar/2006:19:30:41 24/Oct/2006:19:16:19... (4 Replies)
Discussion started by: me_newbie
4 Replies

6. Shell Programming and Scripting

date(ddmmyyyy) sorting

input : 20110730 20110730 20110731 20110731 20110801 20110801 20110801 20110813 20110815 01062011 01062011 OUTPUT : i need to sort this input in such a way so that the latest date comes first. (11 Replies)
Discussion started by: urfrnddpk
11 Replies

7. Shell Programming and Scripting

Sorting the data with date

Hi, PFB the data: C_Random_130417 Java_Random_130518 Perl_Random_120519 Perl_Random_120528 so the values are ending with year,i.e.,130417 i want to sort the values with date. i want the output like this: Perl_Random_120519 Perl_Random_120528 C_Random_130417 Java_Random_130518 can... (5 Replies)
Discussion started by: arindam guha
5 Replies

8. Shell Programming and Scripting

Sorting by date

I am trying to sort by two columns. The first column in an ID, the second is a date in the form yyyy-mm-dd. I need to sort by the ID column, then in ascending order for the date column (earliest date to most recent date compared to today). Input data: 012-abc 2012-04-25 ... (3 Replies)
Discussion started by: mollydog11
3 Replies

9. Shell Programming and Scripting

Sorting on date basis

I have file data.txt having below data cat data.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 FC 1514 0000764631 01-NOV-13 2.38.11.00.100089 FC 1514 0000856571 01-NOV-13 2.38.11.00.100089 IN 300.32... (1 Reply)
Discussion started by: ranabhavish
1 Replies

10. UNIX for Dummies Questions & Answers

Sorting on fields for last date

Hi all, I have a file with a list of rpm's that have different dates. I am trying to just grab the latest rpm and install date, and discard the rest. The file has 1000's of entries all with different names and dates. I have tried sort -k on the file and I am not grabbing the info, ... (4 Replies)
Discussion started by: gartie
4 Replies
Moose::Meta::Attribute::Native::Trait::Array(3) 	User Contributed Perl Documentation	   Moose::Meta::Attribute::Native::Trait::Array(3)

NAME
Moose::Meta::Attribute::Native::Trait::Array - Helper trait for ArrayRef attributes VERSION
version 2.1202 SYNOPSIS
package Stuff; use Moose; has 'options' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, handles => { all_options => 'elements', add_option => 'push', map_options => 'map', filter_options => 'grep', find_option => 'first', get_option => 'get', join_options => 'join', count_options => 'count', has_options => 'count', has_no_options => 'is_empty', sorted_options => 'sort', }, ); no Moose; 1; DESCRIPTION
This trait provides native delegation methods for array references. DEFAULT TYPE
If you don't provide an "isa" value for your attribute, it will default to "ArrayRef". PROVIDED METHODS
o count Returns the number of elements in the array. $stuff = Stuff->new; $stuff->options( [ "foo", "bar", "baz", "boo" ] ); print $stuff->count_options; # prints 4 This method does not accept any arguments. o is_empty Returns a boolean value that is true when the array has no elements. $stuff->has_no_options ? die "No options! " : print "Good boy. "; This method does not accept any arguments. o elements Returns all of the elements of the array as an array (not an array reference). my @option = $stuff->all_options; print "@options "; # prints "foo bar baz boo" This method does not accept any arguments. o get($index) Returns an element of the array by its index. You can also use negative index numbers, just as with Perl's core array handling. my $option = $stuff->get_option(1); print "$option "; # prints "bar" If the specified element does not exist, this will return "undef". This method accepts just one argument. o pop Just like Perl's builtin "pop". This method does not accept any arguments. o push($value1, $value2, value3 ...) Just like Perl's builtin "push". Returns the number of elements in the new array. This method accepts any number of arguments. o shift Just like Perl's builtin "shift". This method does not accept any arguments. o unshift($value1, $value2, value3 ...) Just like Perl's builtin "unshift". Returns the number of elements in the new array. This method accepts any number of arguments. o splice($offset, $length, @values) Just like Perl's builtin "splice". In scalar context, this returns the last element removed, or "undef" if no elements were removed. In list context, this returns all the elements removed from the array. This method requires at least one argument. o first( sub { ... } ) This method returns the first matching item in the array, just like List::Util's "first" function. The matching is done with a subroutine reference you pass to this method. The subroutine will be called against each element in the array until one matches or all elements have been checked. Each list element will be available to the sub in $_. my $found = $stuff->find_option( sub {/^b/} ); print "$found "; # prints "bar" This method requires a single argument. o first_index( sub { ... } ) This method returns the index of the first matching item in the array, just like List::MoreUtils's "first_index" function. The matching is done with a subroutine reference you pass to this method. The subroutine will be called against each element in the array until one matches or all elements have been checked. Each list element will be available to the sub in $_. This method requires a single argument. o grep( sub { ... } ) This method returns every element matching a given criteria, just like Perl's core "grep" function. This method requires a subroutine which implements the matching logic; each list element will be available to the sub in $_. my @found = $stuff->filter_options( sub {/^b/} ); print "@found "; # prints "bar baz boo" This method requires a single argument. o map( sub { ... } ) This method transforms every element in the array and returns a new array, just like Perl's core "map" function. This method requires a subroutine which implements the transformation; each list element will be available to the sub in $_. my @mod_options = $stuff->map_options( sub { $_ . "-tag" } ); print "@mod_options "; # prints "foo-tag bar-tag baz-tag boo-tag" This method requires a single argument. o reduce( sub { ... } ) This method turns an array into a single value, by passing a function the value so far and the next value in the array, just like List::Util's "reduce" function. The reducing is done with a subroutine reference you pass to this method; each list element will be available to the sub in $_. my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } ); print "$found "; # prints "foobarbazboo" This method requires a single argument. o sort o sort( sub { ... } ) Returns the elements of the array in sorted order. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b in this subroutine, you will need to use $_[0] and $_[1]. # ascending ASCIIbetical my @sorted = $stuff->sort_options(); # Descending alphabetical order my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } ); print "@sorted_options "; # prints "foo boo baz bar" This method accepts a single argument. o sort_in_place o sort_in_place( sub { ... } ) Sorts the array in place, modifying the value of the attribute. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. This method does not define a return value. This method accepts a single argument. o shuffle Returns the elements of the array in random order, like "shuffle" from List::Util. This method does not accept any arguments. o uniq Returns the array with all duplicate elements removed, like "uniq" from List::MoreUtils. This method does not accept any arguments. o join($str) Joins every element of the array using the separator given as argument, just like Perl's core "join" function. my $joined = $stuff->join_options(':'); print "$joined "; # prints "foo:bar:baz:boo" This method requires a single argument. o set($index, $value) Given an index and a value, sets the specified array element's value. This method returns the value at $index after the set. This method requires two arguments. o delete($index) Removes the element at the given index from the array. This method returns the deleted value. Note that if no value exists, it will return "undef". This method requires one argument. o insert($index, $value) Inserts a new element into the array at the given index. This method returns the new value at $index. This method requires two arguments. o clear Empties the entire array, like "@array = ()". This method does not define a return value. This method does not accept any arguments. o accessor($index) o accessor($index, $value) This method provides a get/set accessor for the array, based on array indexes. If passed one argument, it returns the value at the specified index. If passed two arguments, it sets the value of the specified index. When called as a setter, this method returns the new value at $index. This method accepts one or two arguments. o natatime($n) o natatime($n, $code) This method returns an iterator which, on each call, returns $n more items from the array, in order, like "natatime" from List::MoreUtils. If you pass a coderef as the second argument, then this code ref will be called on each group of $n elements in the array until the array is exhausted. This method accepts one or two arguments. o shallow_clone This method returns a shallow clone of the array reference. The return value is a reference to a new array with the same elements. It is shallow because any elements that were references in the original will be the same references in the clone. BUGS
See "BUGS" in Moose for details on reporting bugs. AUTHORS
o Stevan Little <stevan.little@iinteractive.com> o Dave Rolsky <autarch@urth.org> o Jesse Luehrs <doy@tozt.net> o Shawn M Moore <code@sartak.org> o XXXX XXX'XX (Yuval Kogman) <nothingmuch@woobling.org> o Karen Etheridge <ether@cpan.org> o Florian Ragwitz <rafl@debian.org> o Hans Dieter Pearcey <hdp@weftsoar.net> o Chris Prather <chris@prather.org> o Matt S Trout <mst@shadowcat.co.uk> COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2014-01-19 Moose::Meta::Attribute::Native::Trait::Array(3)
All times are GMT -4. The time now is 07:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy