Solaris had a sort bug once I recall, but it was more subtle. Try using the -k method of specifying fields and sort direction and such. The +1 -2 notation is obsolescent - LINUX does not have it any more, and 0-based! The -k notation is 1-based, not zero-based, which might be more normal human friendly. BTW, +1 says sort on column 2 and following. I suppose column 1 is the file name?
Some sort of persistent JAVA container could do the testing and storing without a sort, perhaps in a tree. You can put the data into a structure mapped to a flat file, for instance. One possible advantage is that you can prune the set on the fly, if you are not interested in the full set. Also, you can do controlled thread parallelism. It is a lot faster than sort or an SQL RDBMS ETL approach.
Sort can also be sped up with parallelism in bash, on nicer systems with /dev/fd/[0-9]* and ksh (or using named pipes), using sort merge and pipes:
Hi All,
I have a file 1.txt which has the duplicate dns entries as shown:
Name: 000f9fbc6738.net.in|Addresses: 10.241.66.169, 10.84.2.222,212.241.66.170
Name: 001371e8ed3e.net.in|Addresses: 10.241.65.153, 10.84.1.101
Name: 00e06f5bd42a.net.in|Addresses: 10.72.19.218,... (6 Replies)
My data is something like shown below.
date1 date2 aaa bbbb ccccc
date3 date4 dddd eeeeeee ffffffffff ggggg hh
I want the output like this
date1date2 aaa eeeeee
I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
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)
Hi Everybody,
I am just new to UNIX as well as to this forum. I have a text file with 10,000 coloumns and each coloumn contains values separated by space. I want to separate them into new coloumns..the file is something like this
as ad af 1 A
as ad af 1 D
...
...
1 and A are in one... (7 Replies)
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)
Hi All, Need Suggestion, Want to sort a file using awk & sed to get required, output as below, such that each LUN shows correct WWPN and FA port Numbers correctly:
Required output:
01FB 10000000c97843a2 8C 0
01FB 10000000c96fb279 9C 0
22AF 10000000c97843a2 8C 0
22AF 10000000c975adbd ... (10 Replies)
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)
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)
Any good way to check if code has the required output
# /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts
net.ipv4.icmp_echo_ignore_broadcasts = 1
/sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "= 1"
net.ipv4.icmp_echo_ignore_broadcasts = 1
What I can think of is above, and it... (16 Replies)
I have the below contents in a file after making the below curl call
curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test
"state" : "Disconnected",, "Rno" : "5554f1d2"
"state" : "Disconnected",, "Rno" : "10587563"
"state" : "Disconnected",, "Rno" :... (2 Replies)
Discussion started by: Vaibhav H
2 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)