Sponsored Content
Full Discussion: using Unix sort command
Top Forums UNIX for Dummies Questions & Answers using Unix sort command Post 302362776 by Scrutinizer on Saturday 17th of October 2009 01:50:48 PM
Old 10-17-2009
Code:
awk 'NR==FNR {A[$1]=$0; next} {print A[$1]}' fileA fileB

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies

2. UNIX for Dummies Questions & Answers

UNIX sort command

Need some help with the sort command. I have a large file which needs sorted on the third field separated by : and within the third field, I need it sorted by second field or everything after the . An example of my file is here and for example, the first line I need :ROUTER2.SFLDMI: sorted on the... (2 Replies)
Discussion started by: numele
2 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

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

5. UNIX for Advanced & Expert Users

Sort command using unix

Hello, I have a file with 'tab' separated columns. The first column of the file contains integer values. Now I want to sort the first column in ascending order. Can someone help me on this... thanks in advance (1 Reply)
Discussion started by: koneru_18
1 Replies

6. UNIX for Dummies Questions & Answers

New to Unix command line and have a question about the "sort" command

I am going through the Unix Made Easy second edition book by John Muster. So far it's been very informative and I can tell it may be a bit out of date. In one of the exercises it talks about the "sort" command and using it to sort column's of data etc. The "sort" command has changed a bit and... (1 Reply)
Discussion started by: budfoxcat
1 Replies

7. Shell Programming and Scripting

Help to sort out... Possible use of sort command

I have an input like 4.3.6.66 4.3.6.67 4.3.6.70 4.3.6.25 4.3.6.15 4.3.6.54 4.3.6.44 4.3.6.34 4.3.6.24 4.3.6.14 4.3.6.53 4.3.6.43 4.3.6.49 4.3.6.33 4.3.6.52 4.3.6.19 4.3.6.58 4.3.6.42 (5 Replies)
Discussion started by: dnam9917
5 Replies

8. Linux

sort command in centos unix

Iam working in centos linux operating system. Consider the following file by name emp 1008 Vijay 40 1009 Rekha 34 1010 Shreyas 40 1011 Sanjay 40 sort command is not working. I gave sort emp The command is not working Can somebody send the options under centos linux (1 Reply)
Discussion started by: jpachar
1 Replies

9. UNIX for Dummies Questions & Answers

UNIX sort

Hi I have below pattern A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: pens 4 B:Bags 4 A: cells 6 A: jobs 6 Output I need : A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: cells 6 A: jobs 6 ... (7 Replies)
Discussion started by: pkkanduk
7 Replies
sort(3pm)						 Perl Programmers Reference Guide						 sort(3pm)

NAME
sort - perl pragma to control sort() behaviour SYNOPSIS
use sort 'stable'; # guarantee stability use sort '_quicksort'; # use a quicksort algorithm use sort '_mergesort'; # use a mergesort algorithm use sort 'defaults'; # revert to default behavior no sort 'stable'; # stability not important use sort '_qsort'; # alias for quicksort my $current = sort::current(); # identify prevailing algorithm DESCRIPTION
With the "sort" pragma you can control the behaviour of the builtin "sort()" function. In Perl versions 5.6 and earlier the quicksort algorithm was used to implement "sort()", but in Perl 5.8 a mergesort algorithm was also made available, mainly to guarantee worst case O(N log N) behaviour: the worst case of quicksort is O(N**2). In Perl 5.8 and later, quick- sort defends against quadratic behaviour by shuffling large arrays before sorting. A stable sort means that for records that compare equal, the original input ordering is preserved. Mergesort is stable, quicksort is not. Stability will matter only if elements that compare equal can be distinguished in some other way. That means that simple numerical and lexical sorts do not profit from stability, since equal elements are indistinguishable. However, with a comparison such as { substr($a, 0, 3) cmp substr($b, 0, 3) } stability might matter because elements that compare equal on the first 3 characters may be distinguished based on subsequent characters. In Perl 5.8 and later, quicksort can be stabilized, but doing so will add overhead, so it should only be done if it matters. The best algorithm depends on many things. On average, mergesort does fewer comparisons than quicksort, so it may be better when compli- cated comparison routines are used. Mergesort also takes advantage of pre-existing order, so it would be favored for using "sort()" to merge several sorted arrays. On the other hand, quicksort is often faster for small arrays, and on arrays of a few distinct values, repeated many times. You can force the choice of algorithm with this pragma, but this feels heavy-handed, so the subpragmas beginning with a "_" may not persist beyond Perl 5.8. The default algorithm is mergesort, which will be stable even if you do not explicitly demand it. But the stability of the default sort is a side-effect that could change in later versions. If stability is important, be sure to say so with a use sort 'stable'; The "no sort" pragma doesn't forbid what follows, it just leaves the choice open. Thus, after no sort qw(_mergesort stable); a mergesort, which happens to be stable, will be employed anyway. Note that no sort "_quicksort"; no sort "_mergesort"; have exactly the same effect, leaving the choice of sort algorithm open. CAVEATS
This pragma is not lexically scoped: its effect is global to the program it appears in. That means the following will probably not do what you expect, because both pragmas take effect at compile time, before either "sort()" happens. { use sort "_quicksort"; print sort::current . " "; @a = sort @b; } { use sort "stable"; print sort::current . " "; @c = sort @d; } # prints: # quicksort stable # quicksort stable You can achieve the effect you probably wanted by using "eval()" to defer the pragmas until run time. Use the quoted argument form of "eval()", not the BLOCK form, as in eval { use sort "_quicksort" }; # WRONG or the effect will still be at compile time. Reset to default options before selecting other subpragmas (in case somebody carelessly left them on) and after sorting, as a courtesy to others. { eval 'use sort qw(defaults _quicksort)'; # force quicksort eval 'no sort "stable"'; # stability not wanted print sort::current . " "; @a = sort @b; eval 'use sort "defaults"'; # clean up, for others } { eval 'use sort qw(defaults stable)'; # force stability print sort::current . " "; @c = sort @d; eval 'use sort "defaults"'; # clean up, for others } # prints: # quicksort # stable Scoping for this pragma may change in future versions. perl v5.8.0 2002-06-01 sort(3pm)
All times are GMT -4. The time now is 01:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy