Have a text file containing 4 columns, the 4th column is sorted numerically in descending order. The 2nd column is alpha text. Been able to get the 4th column to sort in descending order. The 2nd column sorts correctly but it's also in reverse. Would like to be able to keep the 4th column sort numerically descending while the 2nd column is sorted a-z, not z-a. This is what I have and can't seem to get it to work because everything is reversed.
M 47 HIS:LOT 32 DUTY 2 MIKE, FINISHED
MIKE ACTIVE STATUS
23TASK YES GOOD
100TASK NO GOOD
========================================
M 47 HIS:LOT 1 DUTY 1 MIKE, FINISHED
MIKE ACTIVE STATUS
23TASK YES GOOD
... (7 Replies)
Hello all,
I have a test file that has the format:
.....
O
3.694950 -.895050 1.480000
O
5.485050 .895050 1.480000
Ti
-4.590000 4.590000 2.960000
Ti
-2.295000 ... (5 Replies)
I'm looking for a sort command that will sort by zip code first then by last name. (zip code is the last field, last name is first field)
data file looks like this.
Hope Bob 1234 Main ST. Colorado Springs, CO 80920
I was thinking along the lines of:
sort -k9n address.data //for the... (2 Replies)
I was trying to check for the sort of some columns (say 1-10) of particular file. Now, by default, the Unix sort uses as a separator whitespace (e.g. if you have 'foo bar' then it separates it into 'foo' and 'bar' to use as keys)
Now, I know which particular columns I want to use as the sort... (1 Reply)
Hi all.
Is there a way that I can use the sort command too sort the following field by earliest time (12:00AM) to latest time (11:59PM)?
07:12PM
07:53PM
07:54PM
08:07PM
10:15AM
10:21AM
TIA!!!!!! (1 Reply)
Hello,
I have a large data file:
1234 8888 bbb
2745 8888 bbb
9489 8888 bbb
1234 8888 aaa
4838 8888 aaa
3977 8888 aaa
I need to remove duplicate lines (where the first column is the duplicate). I have been using:
sort file.txt | uniq -w4 > newfile.txt
However, it seems to keep the... (11 Replies)
Hi Guys,
I have a file to be sorted and uniq with the following format.
S00001002|01|20021231
S00001002|01|20011031
S00001006|01|20120430
S00001006|01|20111231
S00001006|01|20111031
S00001006|01|20110831
S00001006|01|20110731
S00001006|01|20101231
S00001006|01|20091231... (5 Replies)
I have a file like this:
/vol/eng_app_0103z
/vol/eng_app_0103z
/vol/eng_app_0120z
/vol/eng_app_0126z
/vol/eng_app_0144z
/vol/eng_app_0150z
/vol/eng_app_0154z
/vol/eng_app_01551z
/vol/eng_app_01552z
/vol/eng_app_0155z
/vol/eng_app_0164z
/vol/eng_app_0199zWhen I use the sort command... (3 Replies)
I have a question about what the sort command is doing.
Here is some sample data:
348201310013RVE 2
600201310013GFJ 70
3302013020101NS 40
600201309013GFJ 70
The sort command that is running is as follows:
sort -k 1,3 -k 12,4 input.txt > output.txt
... (6 Replies)
Discussion started by: Drenhead
6 Replies
LEARN ABOUT DEBIAN
sort::key::natural
Sort::Key::Natural(3pm) User Contributed Perl Documentation Sort::Key::Natural(3pm)NAME
Sort::Key::Natural - fast natural sorting
SYNOPSIS
use Sort::Key::Natural qw(natsort);
my @data = qw(foo1 foo23 foo6 bar12 bar1
foo bar2 bar-45 foomatic b-a-r-45);
my @sorted = natsort @data;
print "@sorted
";
# prints:
# b-a-r-45 bar1 bar2 bar12 bar-45 foo foo1 foo6 foo23 foomatic
use Sort::Key::Natural qw(natkeysort);
my @objects = (...);
my @sorted = natkeysort { $_->get_id } @objects;
DESCRIPTION
This module extends the Sort::Key family of modules to support natural sorting.
Under natural sorting, strings are split at word and number boundaries, and the resulting substrings are compared as follows:
o numeric substrings are compared numerically
o alphabetic substrings are compared lexically
o numeric substrings come always before alphabetic substrings
Spaces, symbols and non-printable characters are only considered for splitting the string into its parts but not for sorting. For instance
"foo-bar-42" is broken in three substrings "foo", "bar" and 42 and after that the dashes are ignored.
Note, that the sorting is case sensitive. To do a case insensitive sort you have to convert the keys explicitly:
my @sorted = natkeysort { lc $_ } @data
Also, once this module is loaded, the new type "natural" (or "nat") will be available from Sort::Key::Maker. For instance:
use Sort::Key::Natural;
use Sort::Key::Maker i_rnat_keysort => qw(integer -natural);
creates a multikey sorter "i_rnat_keysort" accepting two keys, the first to be compared as an integer and the second in natural descending
order.
There is also an alternative set of natural sorting functions that recognize floating point numbers. They use the key type "natwf"
(abreviation of "natural_with_floats").
FUNCTIONS
the functions that can be imported from this module are:
natsort @data
returns the elements of @data sorted in natural order.
rnatsort @data
returns the elements of @data sorted in natural descending order.
natkeysort { CALC_KEY($_) } @data
returns the elements on @array naturally sorted by the keys resulting from applying them "CALC_KEY".
rnatkeysort { CALC_KEY($_) } @data
is similar to "natkeysort" but sorts the elements in descending order.
natsort_inplace @data
rnatsort_inplace @data
natkeysort_inplace { CALC_KEY($_) } @data
rnatkeysort_inplace { CALC_KEY($_) } @data
these functions are similar respectively to "natsort", "rnatsort", "natsortkey" and "rnatsortkey", but they sort the array @data in
place.
$key = mkkey_natural $string
given $string, returns a key that can be compared lexicographically to another key obtained in the same manner, results in the same
order as comparing the former strings as in the natural order.
If the argument $key is not provided it defaults to $_.
natwfsort @data
rnatwfsort @data
natkeywfsort { CALC_KEY($_) } @data
rnatkeywfsort { CALC_KEY($_) } @data
natwfsort_inplace @data
rnatwfsort_inplace @data
natkeywfsort_inplace { CALC_KEY($_) } @data
rnatkeywfsort_inplace { CALC_KEY($_) } @data
mkkey_natural_with_floats $key
this ugly named set of functions perform in the same way as its s/natwf/nat/ counterpart with the difference that they honor floating
point numbers embeded inside the strings.
In this context a floating point number is a string matching the regular expression "/[+-]?d+(.d*)?/". Note that numbers with an
exponent part (i.e. "1.12E-12") are not recognized as such.
Note also that numbers without an integer part (i.e. .2 or "-.12") are not supported either.
SEE ALSO
Sort::Key, Sort::Key::Maker.
Other module providing similar functionality is Sort::Naturally.
COPYRIGHT AND LICENSE
Copyright (C) 2006, 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::Natural(3pm)