12-07-2019
Quote:
Originally Posted by
Scrutinizer
@Ravinder nice different approach, in case the sort utility understands stable sort.
Thank you S. So you mean sort command's stable utility is not supported by all O.S systems. Sorry I only run it on a online terminal which has a GNU sort, not sure about any other O.S systems,if any details you want me to add then feel free to let me know I will add it in my answer then, cheers.
Thanks,
R. Singh
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
This is my input file:
ali 5 usa abc
abu 4 uk bca
alan 6 brazil bac
pinky 10 utah sdc
My desired output:
pinky 10 utah sdc
alan 6 brazil bac
ali 5 usa abc
abu 4 uk bca
Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Discussion started by: patrick87
3 Replies
2. Shell Programming and Scripting
I have an input file like this...
AAAlkalines Energizer
AAAlkalines Energizer
AAAlkalines Energizer
AAAlkalines Sunlight
AAAlkalines Sunlight
AAAlkalines Sunlight
AAAlkalines Energizer
AAAlkalines Energizer
AAAlkalines Energizer
AAASalines ... (7 Replies)
Discussion started by: malcomex999
7 Replies
3. Shell Programming and Scripting
Hi,
My input file is
$cat samp
1 siva
1 raja
2 siva
1 siva
2 raja
4 venkat
i want sort this name wise...alos need to remove duplicate lines.
i am using
cat samp|awk '{print $2,$1}'|sort -u
it showing
raja 1 (3 Replies)
Discussion started by: rsivasan
3 Replies
4. UNIX for Dummies Questions & Answers
I have a column of numbers in the following format:
1.722e-05
2.018e-05
2.548e-05
2.747e-05
7.897e-05
4.016e-05
4.613e-05
4.613e-05
5.151e-05
5.151e-05
5.151e-05
6.1e-05
6.254e-05
7.04e-05
7.12e-05
7.12e-05 (6 Replies)
Discussion started by: evelibertine
6 Replies
5. UNIX for Dummies Questions & Answers
If my data is numerical :
1 = 101
2 = 102
3 = 104
4 = 104
7 = 103
8 = 103
9 = 105
I need the result like below:
1 = 101
2 = 102
3 = 103
4 = 103
7 = 104
8 = 104
9 = 105 (4 Replies)
Discussion started by: GeodusT
4 Replies
6. Shell Programming and Scripting
Hi Guru,
I need some help regarding awking the output so it only show the first line (based on column) of each row.
So If column has 1, three row, then it only show the first line of that row, based on similar character in column 1. So i am trying to achieve a sort, based on column one and... (3 Replies)
Discussion started by: Junes
3 Replies
7. Shell Programming and Scripting
Hi,
i need to sort content of files based on a specific value. An example as below.
Input1.txt
Col_1
SW_MH2_ST
ST_F72_9S
SW_MH3_S6
Col_2
SW_MH3_AS7
ST_S15_9CH
SW_MH3_AS8
SW_MH3_ST
Col_3
ST_M93_SZ
ST_C16_TC (12 Replies)
Discussion started by: redse171
12 Replies
8. Shell Programming and Scripting
Hi,
I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column)
The input is for example, after sorted:
K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies
9. UNIX for Beginners Questions & Answers
I have a csv file as shown below,
xop_thy 80 avr_njk 50 str_nyu 60
avr_irt 70 str_nhj 60 avr_ngt 50
str_tgt 80 xop_nmg 50 xop_nth 40
cyv_gty 40 cop_thl 40 vir_tyk 80
vir_plo 20 vir_thk 40 ijk_yuc 70
cop_thy 70 ijk_yuc 80 irt_hgt 80
I need to align/sort the csv file based... (7 Replies)
Discussion started by: dineshkumarsrk
7 Replies
10. Shell Programming and Scripting
How to sort the following output based on lowest to highest BE?
The following sort does not work.
$ sort -t. -k1,1n -k2,2n bfd.txt
BE31.116 0s 0s DOWN DAMP
BE31.116 0s 0s DOWN DAMP
BE31.117 0s 0s ... (7 Replies)
Discussion started by: sand1234
7 Replies
LEARN ABOUT NETBSD
radixsort
RADIXSORT(3) BSD Library Functions Manual RADIXSORT(3)
NAME
radixsort, sradixsort -- radix sort
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <limits.h>
#include <stdlib.h>
int
radixsort(const u_char **base, int nmemb, u_char *table, u_int endbyte);
int
sradixsort(const u_char **base, int nmemb, u_char *table, u_int endbyte);
DESCRIPTION
The radixsort() and sradixsort() functions are implementations of radix sort.
These functions sort an nmemb element array of pointers to byte strings, with the initial member of which is referenced by base. The byte
strings may contain any values. End of strings is denoted by character which has same weight as user specified value endbyte. endbyte has
to be between 0 and 255.
Applications may specify a sort order by providing the table argument. If non-NULL, table must reference an array of UCHAR_MAX + 1 bytes
which contains the sort weight of each possible byte value. The end-of-string byte must have a sort weight of 0 or 255 (for sorting in
reverse order). More than one byte may have the same sort weight. The table argument is useful for applications which wish to sort differ-
ent characters equally, for example, providing a table with the same weights for A-Z as for a-z will result in a case-insensitive sort. If
table is NULL, the contents of the array are sorted in ascending order according to the ASCII order of the byte strings they reference and
endbyte has a sorting weight of 0.
The sradixsort() function is stable, that is, if two elements compare as equal, their order in the sorted array is unchanged. The
sradixsort() function uses additional memory sufficient to hold nmemb pointers.
The radixsort() function is not stable, but uses no additional memory.
These functions are variants of most-significant-byte radix sorting; in particular, see D.E. Knuth's Algorithm R and section 5.2.5, exercise
10. They take linear time relative to the number of bytes in the strings.
RETURN VALUES
Upon successful completion 0 is returned. Otherwise, -1 is returned and the global variable errno is set to indicate the error.
ERRORS
[EINVAL] The value of the endbyte element of table is not 0 or 255.
Additionally, the sradixsort() function may fail and set errno for any of the errors specified for the library routine malloc(3).
SEE ALSO
sort(1), qsort(3)
Knuth, D.E., "Sorting and Searching", The Art of Computer Programming, Vol. 3, pp. 170-178, 1968.
Paige, R., "Three Partition Refinement Algorithms", SIAM J. Comput., No. 6, Vol. 16, 1987.
McIlroy, P., "Computing Systems", Engineering Radix Sort, Vol. 6:1, pp. 5-27, 1993.
HISTORY
The radixsort() function first appeared in 4.4BSD.
BSD
January 27, 1994 BSD