Sponsored Content
Full Discussion: sort split merge -u unique
Top Forums Shell Programming and Scripting sort split merge -u unique Post 302551799 by jbr950 on Wednesday 31st of August 2011 04:54:56 PM
Old 08-31-2011
sort split merge -u unique

Hi, this is about sorting a very large file (like 10 gb) to keep lines with unique entries across SOME of the columns.

The line originally looked like this:

Code:
sort -u -k2,2 -k3,3n -k4,4n -k5,5n -k6,6n file_unsorted > file_sorted

please note the -u flag.

The problem is that this single command is taking more than 12 hours with 10 g of memory and I am looking for a way to speed things up.

I have heard that splitting a large file into subfiles, then sorting each subfile and then merging back together with the sort command can work, but I am imaging this will not work because I'm using the -u flag to keep only unique rows.

maybe split and then sort first WITHOUT the -u flag and then sort -m -u -k2,2 -k3,3n -k4,4n -k5,5n -k6,6n subfiles ?

I'm thinking of ways to test that, but please let me know if you have any ideas for me!

Thank you kindly.

Jonathan

Last edited by radoulov; 08-31-2011 at 06:01 PM.. Reason: Please use code tags for code and data samples, thank you
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort and Unique in Perl

Hi, May I know, if a pipe separated File is large, what is the best method to calculate the unique row count of 3rd column and get a list of unique value of the 3rdcolum? Thanks in advance! (20 Replies)
Discussion started by: deepakwins
20 Replies

2. UNIX for Dummies Questions & Answers

split a file with unique sets

This may sound like a trivial problem, but I still need some help: I have a file with ids and I want to split it 'n' ways (could be any number) into files: 1 1 1 2 2 3 3 4 5 5 Let's assume 'n' is 3, and we cannot have the same id in two different partitions. So the partitions may... (8 Replies)
Discussion started by: ChicagoBlues
8 Replies

3. Shell Programming and Scripting

Awk sort and unique

Input file --------- 12:name1:|host1|host1|host2|host1 13:name2:|host1|host1|host2|host3 14:name3: ...... Required output --------------- 12:name1:host1(2)|host1(1) 13:name2:host1(2)|host2(1)|host3(1) 14:name3: where (x) - Count how many times field appears in last column ... (3 Replies)
Discussion started by: greycells
3 Replies

4. Shell Programming and Scripting

How to merge columns into lines, using unique keys?

I would really appreciate a sulution for this : invoice# client# 5929 231 4358 231 2185 231 6234 231 1166 464 1264 464 3432 464 1720 464 9747 464 1133 791 4930 791 5496 791 6291 791 8681 989 3023 989 (2 Replies)
Discussion started by: hemo21
2 Replies

5. UNIX for Dummies Questions & Answers

How to count specific columns and merge with unique ones?

Hi. I am not sure the title gives an optimal description of what I want to do. I have several text files that contain data in many columns. All the files are organized the same way, but the data in the columns might differ. I want to count the number of times data occur in specific columns,... (0 Replies)
Discussion started by: JamesT
0 Replies

6. UNIX for Dummies Questions & Answers

Print unique lines without sort or unique

I would like to print unique lines without sort or unique. Unfortunately the server I am working on does not have sort or unique. I have not been able to contact the administrator of the server to ask him to add it for several weeks. (7 Replies)
Discussion started by: cokedude
7 Replies

7. Shell Programming and Scripting

How to merge two files with unique values matching.?

I have one script as below: #!/bin/ksh Outputfile1="/home/OutputFile1.xls" Outputfile2="/home/OutputFile2.xls" InputFile1="/home/InputFile1.sql" InputFile2="/home/InputFile2.sql" echo "Select hobby, class, subject, sports, rollNumber from Student_Table" >> InputFile1 echo "Select rollNumber... (3 Replies)
Discussion started by: Sharma331
3 Replies

8. Shell Programming and Scripting

Sort unique

Hi, I have an input file that I have sorted in a previous stage by $1 and $4. I now need something that will take the first record from each group of data based on the key being $1 Input file 1000AAA|"ZZZ"|"Date"|"1"|"Y"|"ABC"|""|AA 1000AAA|"ZZZ"|"Date"|"2"|"Y"|"ABC"|""|AA... (2 Replies)
Discussion started by: Ads89
2 Replies

9. UNIX for Beginners Questions & Answers

Merge 4 bim files by keeping only the overlapping variants (unique rs values )

Dear community, I am facing a problem and I kindly ask your help: I have 4 different data sets consisted from 3 different types of array. On each file, column 1 is chromosome position, column 2 is SNP id etc... Lets say I have the following (bim) datasets: x2014: 1 rs3094315... (4 Replies)
Discussion started by: fondan
4 Replies
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)
All times are GMT -4. The time now is 07:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy