I have the following output where I need to sort the second column numerically (starting with IBMULT3580-TD10 and ending in IBMULT3580-TD123)
I'm trying to apply the sort, and the output is getting sorted, but not numerically:
I tried adding -n but it produces a rather weird output, seemingly in random order. Any suggestions how to sort this string numerically? I can't figure it out from the sort man page. TIA!
Hi All,
First time poster.
I have a text file that as many entries like below (single line):
egrep RspTime conlb.txt |more
S(xxx.xxx.xxx.xxx:5050:UP) Hits(13358983, 2/sec, P) ATr(2) Mbps(0.07) BWlmt(0 kbits) RspTime(16.50 ms)
...
I am trying to sort on the RspTime from highest to lowest... (4 Replies)
I would like to sort a large ascii file. Primary sort on the 1st column, and secondary sort on the second column. The file consists of 10 rows of header text and then thousands of rows with 6 columns. I want to sort all of the rows by the first column and second column. As an example, here is... (2 Replies)
Hi all
i am facing a problem in sorting command. The script depending on the sorting command works fine only if ascii sorting is done.
i need to know how to find out how to perform ascii sorting. sorting is case insensitive in
my file has data in the following format.
AA/BB/
AAA/BB\
also... (1 Reply)
Looking for help for sort, I learned that for sorting numbers I use:
sort -n
but it seems that that is not enough when you have numbers like 0.2000E+7 for example, sort -n will not worry about the E+7 part, and will just sort the numbers like 0.2000.
Exapmle:
cat example.txt
.91000E+07... (9 Replies)
hi all,
i need help on sorting data.
i have a file as below
/home/oracle $ cat 234.txt
+1234
-2356
-1001
+231
0023
-0987
+19000
65487
6
after sorting i want the output as below
-2356
-1001 (2 Replies)
Hello,
I have a file such as this:
chr1
chr2
chr1
chr2
chr3
chr10
chr4
chr5
chrz
chr1AI want to sort it, I use this command:
sort -k1 -th -n testfilebut I get this output, how can I fix this?
chr1
chr1
chr10
chr1A
chr2
chr2 (3 Replies)
Hi Guys,
Would appreciate some help on sorting numbers on a file using the sort command. I have tried this and it's not sorting properly. what am i missing?
cat testing_sort
1:21
4:18
2:17
7:14
9:19
3:12
0:16
8:13
5:20
6:15
10:11
sort -t: -nk1,1 -nk2,2 testing_sort (4 Replies)
Hey everybody,
I'm trying to sort scientific numbers in a descending order using the command
sort -gr <file>.
It works fine on a Linux-Server, but doesn't on my macbook pro with OS X 10.10.3 (Yosemite).
I tried to sort the following:
6.38e-10
6.38e-10
1.80e-11
1.00e-10
1.48e-12
And... (9 Replies)
I have variable that contains multiple values of number and also include overpunch(i.e. # $ % etc) character so we want to replace it with numbers.
here are the example:
Code:
11500#.0#
28575$.5$
527#.7#
42".2"
2794 .4
2279!.9!
1067&.7&
926#.6#
2279!.9!
885".5"
11714$.4$
27361'.1'... (1 Reply)
Discussion started by: nadeemrafikhan
1 Replies
LEARN ABOUT DEBIAN
tree::simple::visitor::sort
Tree::Simple::Visitor::Sort(3pm) User Contributed Perl Documentation Tree::Simple::Visitor::Sort(3pm)NAME
Tree::Simple::Visitor::Sort - A Visitor for sorting a Tree::Simple object heirarchy
SYNOPSIS
use Tree::Simple::Visitor::Sort;
# create a visitor object
my $visitor = Tree::Simple::Visitor::Sort->new();
$tree->accept($visitor);
# the tree is now sorted ascii-betically
# set the sort function to
# use a numeric comparison
$visitor->setSortFunction($visitor->NUMERIC);
$tree->accept($visitor);
# the tree is now sorted numerically
# set a custom sort function
$visitor->setSortFunction(sub {
my ($left, $right) = @_;
lc($left->getNodeValue()->{name}) cmp lc($right->getNodeValue()->{name});
});
$tree->accept($visitor);
# the tree's node are now sorted appropriately
DESCRIPTION
This implements a recursive multi-level sort of a Tree::Simple heirarchy. I think this deserves some more explaination, and the best way to
do that is visually.
Given the tree:
1
1.3
1.2
1.2.2
1.2.1
1.1
4
4.1
2
2.1
3
3.3
3.2
3.1
A normal sort would produce the following tree:
1
1.1
1.2
1.2.1
1.2.2
1.3
2
2.1
3
3.1
3.2
3.3
4
4.1
A sort using the built-in REVERSE sort function would produce the following tree:
4
4.1
3
3.3
3.2
3.1
2
2.1
1
1.3
1.2
1.2.2
1.2.1
1.1
As you can see, no node is moved up or down from it's current depth, but sorted with it's siblings. Flexible customized sorting is possible
within this framework, however, this cannot be used for tree-balancing or anything as complex as that.
METHODS
new There are no arguments to the constructor the object will be in its default state. You can use the "setNodeFilter" and
"setSortFunction" methods to customize its behavior.
includeTrunk ($boolean)
Based upon the value of $boolean, this will tell the visitor to include the trunk of the tree in the sort as well.
setNodeFilter ($filter_function)
This method accepts a CODE reference as it's $filter_function argument and throws an exception if it is not a code reference. This code
reference is used to filter the tree nodes as they are sorted. This can be used to gather specific information from a more complex tree
node. The filter function should accept a single argument, which is the current Tree::Simple object.
setSortFunction ($sort_function)
This method accepts a CODE reference as it's $sort_function argument and throws an exception if it is not a code reference. The
$sort_function is used by perl's builtin "sort" routine to sort each level of the tree. The $sort_function is passed two Tree::Simple
objects, and must return 1 (greater than), 0 (equal to) or -1 (less than). The sort function will override and bypass any node filters
which have been applied (see "setNodeFilter" method above), they cannot be used together.
Several pre-built sort functions are provided. All of these functions assume that calling "getNodeValue" on the Tree::Simple object
will return a suitable sortable value.
REVERSE
This is the reverse of the normal sort using "cmp".
NUMERIC
This uses the numeric comparison operator "<=>" to sort.
REVERSE_NUMERIC
The reverse of the above.
ALPHABETICAL
This lowercases the node value before using "cmp" to sort. This results in a true alphabetical sorting.
REVERSE_ALPHABETICAL
The reverse of the above.
If you need to implement one of these sorting routines, but need special handling of your Tree::Simple objects (such as would be done
with a node filter), I suggest you read the source code and copy and modify your own sort routine. If it is requested enough I will
provide this feature in future versions, but for now I am not sure there is a large need.
visit ($tree)
This is the method that is used by Tree::Simple's "accept" method. It can also be used on its own, it requires the $tree argument to be
a Tree::Simple object (or derived from a Tree::Simple object), and will throw and exception otherwise.
It should be noted that this is a destructive action, since the sort happens in place and does not produce a copy of the tree.
BUGS
None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it.
CODE COVERAGE
See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more inforamtion.
SEE ALSO
These Visitor classes are all subclasses of Tree::Simple::Visitor, which can be found in the Tree::Simple module, you should refer to that
module for more information.
ACKNOWLEDGEMENTS
Thanks to Vitor Mori for the idea and much of the code for this Visitor.
AUTHORS
Vitor Mori, <vvvv767@hotmail.com>
stevan little, <stevan@iinteractive.com>
COPYRIGHT AND LICENSE
Copyright 2004, 2005 by Vitor Mori & Infinity Interactive, Inc.
<http://www.iinteractive.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.10.1 2005-07-14 Tree::Simple::Visitor::Sort(3pm)