Hi I would like to sort a csv file. It has 50 fields and approx 1400000 lines. I want to sort by three columns as follows. Say sort on coulmn 5, if entries are equal sort on column 3 if this is also equal sort on column 6.
It seems that this is possible for 5 then 3 i.e.
but it doesn't seem to work for 5 then 3 then 6 i.e.
(that is assuming this is doing what I think).
I know in perl the subroutine to do this would be, this works for smaller files but when I try to run my large file it crashes due to memory issues.
my questions
Would I neeed to write a subroutine to do this ?
I have a large csv file that looks like this:
14 ,M0081,+000000001,200302,+00000100500,
14 ,M0081,+000000004,200301,+00000100500,
14 ,M0081,+000000005,200305,+00000100500,
14 ,M0081,+000000000,200205,+00000100500,
14 ,M0081,+000000008,200204,+00000100500,
... (2 Replies)
HI ALL,
i have a problem when i do a sort sum with many fields.
Is there a limit for fields?
Do you know a solution?
thanks in advance.
the shell is:
# SORT1
SORT1_rcode=777
if ; then
echo "USE $DARSEQ/OTPU.FTPEPREC RECORD F,1000 " > $DARPARSRT/TPEKL508.SORT1_$$.srt
... (6 Replies)
Hi I have following fixed width file and I have to sort on 2 fields
ABC 111222333002555 77788
ABC 111222333004555 77788
ABC 111222333001555 77788
ABC 111222333003555 77788
ABC 111222333005555 77788
one is from field1 to field 3 "ABC" and another is on 14 to 16 "002" (based on first... (1 Reply)
Hi experts,
I am trying sort command with my data but still not getting the expected results.
For example, I have 5 fields data here
c,18:12:45,c,c,c
d,12:34:34,d,d,d
a,13:50:10,a,a,a
b,13:50:50,b,b,b
a,13:50:50,a,a,a
b,14:10:01,b,b,b
c,10:12:45,c,c,c
I want to get
... (3 Replies)
Hey,
I have a file i want to sort. It contains these kind of lines:
FirstName LastName buyID buyType
Eg:
John Doe 22 Car
Jane Simpson 4 Headset
John Doe 11 Telephone
Now if I use the sort command on it
cat purchases.txt | sort -k1,1 -k2,2
it would also sort the third and 4th field:... (4 Replies)
I have a file with contents below
123,502
123,506
123,702
234,101
235,104
456,104
456,100
i want to sort such that i get a unique value in column A, and for those with multiple value in A, i want the lowest value in B.
output should be
123,502
234,101
235,104
456,100 (3 Replies)
I have another file with three columns A,B,C as below
123,1,502
123,2,506
123,3,702
234,4,101
235,5,104
456,6,104
456,7,100
i want to sort such that i get a unique value in column A, and for those with multiple value in A, i want the lowest value in C.
output should be
Code:... (3 Replies)
hi,
i'm having a file stg_ff.txt
which contains 10 fields,which contains millions of records
i need to cat the first 10 rows in the file after doing a sorting on the first two fields i n the file.
can any body help me on this.
regards
Angel (4 Replies)
Please advice in this.
Input file
100,vvvt
201,unb
100,sos
301,abc
99,gang
desired output
99,gang
100,vvvt
100,sos
201,unb
301,abc
Means if first fields are same ( here 100) the do not sort. (4 Replies)
Hi
I have a file as below
<field1> <field2> <field3> ... <field_num1> <field_num2>
Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields.
I tried this and it doesn't sort on the difference field .. Appreciate your help.
cat... (9 Replies)
Discussion started by: newstart
9 Replies
LEARN ABOUT OPENSOLARIS
ldap_sort
ldap_sort(3LDAP) LDAP Library Functions ldap_sort(3LDAP)NAME
ldap_sort, ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp - LDAP entry sorting functions
SYNOPSIS
cc[ flag... ] file... -lldap[ library... ]
#include <lber.h>
#include <ldap.h>
ldap_sort_entries(LDAP *ld, LDAPMessage **chain, char *attr,
int (*cmp)());
ldap_sort_values(LDAP *ld, char **vals, int (*cmp)());
ldap_sort_strcasecmp(char *a, char *b);
DESCRIPTION
These functions are used to sort lists of entries and values retrieved from an LDAP server. ldap_sort_entries() is used to sort a chain of
entries retrieved from an LDAP search call either by DN or by some arbitrary attribute in the entries. It takes ld, the LDAP structure,
which is only used for error reporting, chain, the list of entries as returned by ldap_search_s(3LDAP) or ldap_result(3LDAP). attr is the
attribute to use as a key in the sort or NULL to sort by DN, and cmp is the comparison function to use when comparing values (or individ-
ual DN components if sorting by DN). In this case, cmp should be a function taking two single values of the attr to sort by, and return-
ing a value less than zero, equal to zero, or greater than zero, depending on whether the first argument is less than, equal to, or greater
than the second argument. The convention is the same as used by qsort(3C), which is called to do the actual sorting.
ldap_sort_values() is used to sort an array of values from an entry, as returned by ldap_get_values(3LDAP). It takes the LDAP connection
structure ld, the array of values to sort vals, and cmp, the comparison function to use during the sort. Note that cmp will be passed a
pointer to each element in the vals array, so if you pass the normal char ** for this parameter, cmp should take two char **'s as arguments
(that is, you cannot pass strcasecmp or its friends for cmp). You can, however, pass the function ldap_sort_strcasecmp() for this pur-
pose.
For example:
LDAP *ld;
LDAPMessage *res;
/* ... call to ldap_search_s(), fill in res, retrieve sn attr ... */
/* now sort the entries on surname attribute */
if ( ldap_sort_entries( ld, &res, "sn", ldap_sort_strcasecmp ) != 0 )
ldap_perror( ld, "ldap_sort_entries" );
ATTRIBUTES
See attributes(5) for a description of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|Availability |SUNWcsl (32-bit) |
| |SUNWcslx (64-bit) |
|Interface Stability |Evolving |
+-----------------------------+-----------------------------+
SEE ALSO ldap(3LDAP), ldap_search(3LDAP), ldap_result(3LDAP), qsort(3C), attributes(5)NOTES
The ldap_sort_entries() function applies the comparison function to each value of the attribute in the array as returned by a call to
ldap_get_values(3LDAP), until a mismatch is found. This works fine for single-valued attributes, but may produce unexpected results for
multi-valued attributes. When sorting by DN, the comparison function is applied to an exploded version of the DN, without types. The return
values for all of these functions are declared in the <ldap.h> header file. Some functions may allocate memory which must be freed by the
calling application.
SunOS 5.11 27 Jan 2002 ldap_sort(3LDAP)