Sponsored Content
Full Discussion: Sort on two keys
Top Forums UNIX for Advanced & Expert Users Sort on two keys Post 302210207 by clarcombe on Monday 30th of June 2008 10:31:39 AM
Old 06-30-2008
Thanks for the reply.

Unfortunately I am calling unix from within another program (Datastage). I really wanted to keep it to one unix command but if this is not possible I will have to work around it.

One way I was going to do this was to change the generation of the second key so that it is always in the right order so I only have to use one key.Smilie

Thanks anyway
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

arrow keys / special keys

how to use the arrow keys in shell scripting. is there any special synatax / command for this. i just want to use the arrow keys for navigation. replies appreciated raguram R (3 Replies)
Discussion started by: raguramtgr
3 Replies

2. UNIX for Advanced & Expert Users

sort on multiple keys

Hello, Say I have a file with plain text as shown below. Some columns may have multiple words (like "DESC 1", "DESC 1 2", "DESC 1 2 3"). Let's say the file below has 4 columns: 1st(AA), 2nd(BB), 3rd(DESC 1, ...), 4th(CC 1, ...). 1234567890123456789012345678901234567890 AA BB DESC 1... (1 Reply)
Discussion started by: teqmem
1 Replies

3. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

4. Shell Programming and Scripting

What are public keys in ssh and how do we create the public keys??

Hi All, I am having knowledge on some basics of ssh and wanted to know what are the public keys and how can we create and implement it in connecting server. Please provide the information for the above, it would be helpful for me. Thanks, Ravindra (1 Reply)
Discussion started by: ravi3cha
1 Replies

5. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

6. Shell Programming and Scripting

[SOLVED] Sort on multiple keys

Can you guys pls take a look at this. I need to sort this list of numbers as follows: 2nd col first, then 1st col, then 3rd col, all in reverse (highest to lowest). I'm doing this: sort -k 2,2nr -k 1,1nr -k 3,3gr but, as you see, the 3rd col does not get sorted properly. Any idea... (0 Replies)
Discussion started by: mamboknave
0 Replies

7. Shell Programming and Scripting

Alternate to sort --random-sort

sort --random-sort The full command is path=`find /testdir -maxdepth 1 -mindepth 1 -type d | ***Some sort of sort function*** | head -1` I have a list I want to randomly sort. It works fine in ubuntu but on a 'osx lion' sort dosen't have the --random-sort option. I don't want to... (5 Replies)
Discussion started by: digitalviking
5 Replies

8. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

9. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

10. UNIX for Dummies Questions & Answers

Sort with multiple keys

Please suggest a sort command to achieve the below task. Thanks. I want to sort a file considering multiple keys. Sort Keys: Field 2, Field4 and Field6 Input file vqrs,16,zzz,1235,eq,T abcd,11,zzz,1234,pq,F abcd,10,zzz,1235,pq,F lqrs,15,zzz,1235,eq,T pqrs,12,zzz,1234,eq,F... (3 Replies)
Discussion started by: pretty1234
3 Replies
Sort::Key(3pm)						User Contributed Perl Documentation					    Sort::Key(3pm)

NAME
Sort::Key - the fastest way to sort anything in Perl SYNOPSIS
use Sort::Key qw(keysort nkeysort ikeysort); @by_name = keysort { "$_->{surname} $_->{name}" } @people; # sorting by a numeric key: @by_age = nkeysort { $_->{age} } @people; # sorting by a numeric integer key: @by_sons = ikeysort { $_->{sons} } @people; DESCRIPTION
Sort::Key provides a set of functions to sort lists of values by some calculated key value. It is faster (usually much faster) and uses less memory than other alternatives implemented around perl sort function (ST, GRT, etc.). Multikey sorting functionality is also provided via the companion modules Sort::Key::Multi, Sort::Key::Maker and Sort::Key::Register. FUNCTIONS This module provides a large number of sorting subroutines but they are all variations off the "keysort" one: @sorted = keysort { CALC_KEY($_) } @data that is conceptually equivalent to @sorted = sort { CALC_KEY($a) cmp CALC_KEY($b) } @data and where "CALC_KEY($_)" can be any expression to extract the key value from $_ (not only a subroutine call). For instance, some variations are "nkeysort" that performs a numeric comparison, "rkeysort" that orders the data in descending order, "ikeysort" and "ukeysort" that are optimized versions of "nkeysort" that can be used when the keys are integers or unsigned integers respectively, etc. Also, inplace versions of the sorters are provided. For instance keysort_inplace { CALC_KEY($_) } @data that is equivalent to @data = keysort { CALC_KEY($_) } @data but being (a bit) faster and using less memory. The full list of subroutines that can be imported from this module follows: keysort { CALC_KEY } @array returns the elements on @array sorted by the key calculated applying "{ CALC_KEY }" to them. Inside "{ CALC_KEY }", the object is available as $_. For example: @a=({name=>john, surname=>smith}, {name=>paul, surname=>belvedere}); @by_name=keysort {$_->{name}} @a; This function honours the "use locale" pragma. nkeysort { CALC_KEY } @array similar to keysort but compares the keys numerically instead of as strings. This function honours the "use integer" pragma, i.e.: use integer; my @s=(2.4, 2.0, 1.6, 1.2, 0.8); my @ns = nkeysort { $_ } @s; print "@ns " prints 0.8 1.6 1.2 2.4 2 rnkeysort { CALC_KEY } @array works as nkeysort, comparing keys in reverse (or descending) numerical order. ikeysort { CALC_KEY } @array works as keysort but compares the keys as integers (32 bits or more, no checking is performed for overflows). rikeysort { CALC_KEY } @array works as ikeysort, but in reverse (or descending) order. ukeysort { CALC_KEY } @array works as keysort but compares the keys as unsigned integers (32 bits or more). For instance, it can be used to efficiently sort IP4 addresses: my @data = qw(1.2.3.4 4.3.2.1 11.1.111.1 222.12.1.34 0.0.0.0 255.255.255.0) 127.0.0.1); my @sorted = ukeysort { my @a = split /./; (((($a[0] << 8) + $a[1] << 8) + $a[2] << 8) + $a[3]) } @data; rukeysort { CALC_KEY } @array works as ukeysort, but in reverse (or descending) order. keysort_inplace { CALC_KEY } @array nkeysort_inplace { CALC_KEY } @array ikeysort_inplace { CALC_KEY } @array ukeysort_inplace { CALC_KEY } @array rkeysort_inplace { CALC_KEY } @array rnkeysort_inplace { CALC_KEY } @array rikeysort_inplace { CALC_KEY } @array rukeysort_inplace { CALC_KEY } @array work as the corresponding keysort functions but sorting the array inplace. rsort @array nsort @array rnsort @array isort @array risort @array usort @array rusort @array rsort_inplace @array nsort_inplace @array rnsort_inplace @array isort_inplace @array risort_inplace @array usort_inplace @array rusort_inplace @array are simplified versions of its keysort cousins. They use the own values as the sorting keys. For instance those constructions are equivalent: @sorted = nsort @foo; @sorted = nkeysort { $_ } @foo; @sorted = sort { $a <=> $b } @foo; multikeysorter(@types) multikeysorter_inplace(@types) multikeysorter(&genkeys, @types) multikeysorter_inplace(&genkeys, @types) are the low level interface to the multikey sorting functionality (normally, you should use Sort::Key::Maker and Sort::Key::Register or Sort::Key::Multi instead). They get a list of keys descriptions and return a reference to a multikey sorting subroutine. Types accepted by default are: string, str, locale, loc, integer, int, unsigned_integer, uint, number, num and support for additional types can be added via the register_type subroutine available from Sort::Key::Types or the more friendly interface available from Sort::Key::Register. Types can be preceded by a minus sign to indicate descending order. If the first argument is a reference to a subroutine it is used as the multikey extraction function. If not, the generated sorters expect one as their first argument. Example: my $sorter1 = multikeysorter(sub {length $_, $_}, qw(int str)); my @sorted1 = &$sorter1(qw(foo fo o of oof)); my $sorter2 = multikeysorter(qw(int str)); my @sorted2 = &$sorter2(sub {length $_, $_}, qw(foo fo o of oof)); SEE ALSO
perl sort function, integer, locale. Companion modules Sort::Key::Multi, Sort::Key::Register, Sort::Key::Maker and Sort::Key::Natural. Sort::Key::IPv4, Sort::Key::DateTime and Sort::Key::OID modules add support for additional datatypes to Sort::Key. Sort::Key::External allows one to sort huge lists that do not fit in the available memory. Other interesting Perl sorting modules are Sort::Maker, Sort::Naturally and Sort::External. SUPPORT
To report bugs, send me and email or use the CPAN bug tracking system at <http://rt.cpan.org>. Commercial support Commercial support, professional services and custom software development around this module are available through my current company. Drop me an email with a rough description of your requirements and we will get back to you ASAP. My wishlist If you like this module and you're feeling generous, take a look at my Amazon Wish List: <http://amzn.com/w/1WU1P6IR5QZ42> COPYRIGHT AND LICENSE
Copyright (C) 2005-2007, 2012 by Salvador Fandin~o, <sfandino@yahoo.com>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2012-06-30 Sort::Key(3pm)
All times are GMT -4. The time now is 08:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy