Arbitrary sort orders


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Arbitrary sort orders
# 1  
Old 06-17-2010
Arbitrary sort orders

So, suppose I want to sort something in some arbitrary order... for example, let's say I have "grades" (actually, work evaluation results where I work) that are, from best to worst, E, A, S, D, P. So, I want to sort by a "grade" column with the E's first, then the A's, etc. Is there a reasonably straightforward way to create an arbitrary sort order like this? It can be done readily in awk and other languages, but I'm wondering about the sort command itself.

Another application might also be sorting -h output for the ls or du commands-- sort order T, G, M, K, B (or nothing).
# 2  
Old 06-17-2010
one way, assuming only those letters appear, something like:

Code:
sed 'y/EASDP/ABCDE/' infile | sort | sed 'y/ABCDE/EASDP/'

i.e. transpose your letters to a standard sortable alphabet, then sort, and map back...
# 3  
Old 06-17-2010
Hi.

The command msort is in the Debian repository. One of its features is:
Code:
For each key an arbitrary sort order may be specified. Msort also understands locales.

If not in your repository, see: MSORT

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arbitrary permutation and combination script

#!/bin/bash # permutation_combination.sh # Version: 2.0 # Author : YongYe <complex.invoke@gmail.com> arg0=-1 argv=${3} number=${2} eval ary=({1..${1}}) length=${#ary} percom(){ nsloop i ${1} number${2} ${3} ${4} ${5}; } invoke(){ echo $(percom ${argu} nsloop -1) prtcom $(percom... (1 Reply)
Discussion started by: complex.invoke
1 Replies

2. Shell Programming and Scripting

How to change the orders of the lines in a txt according to its length

I have a txt: a/b/c/d a/b/c b/f/g/v/m I want ot change this txt according to the number of '/' the result should be like: b/f/g/v/m a/b/c/d a/b/c how to do that? Thanks in advance I need shell...sorry, python or perl is a good solution, but i want shell Please use code... (8 Replies)
Discussion started by: Henryyy
8 Replies

3. Shell Programming and Scripting

Sort a bunch of strings by an arbitrary token

I have a bunch of strings that contain, among the tokens, the size of a file. I want sort based on this value, which is always located in the same "column" in each string, with the largest at the top. Thanks (6 Replies)
Discussion started by: stevensw
6 Replies

4. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

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)
Discussion started by: pankaj80
3 Replies

5. Shell Programming and Scripting

Splitting a file by arbitrary values

How do I split a file into unequal line number segments? For example, I have a 100,000 line file that I need to split into 4 or 5 segments and the segments are not uniform, so split will not work in this case. The five segments might be: 27,000 44,512 13,542 2,344 & 12,602. I can accomplish... (4 Replies)
Discussion started by: sitney
4 Replies

6. UNIX for Dummies Questions & Answers

bc arbitrary precision cal lang

Hello all, I don't know ksh that well but when I try to run a simple script using the bc command I get "unexpected '.' ", has any one encouter this or help me. I'm running under redaht 7.2. Here is a simple example: #!/bin/ksh # kilo=`echo "2495 * .25"|bc` if then echo "LESS THEN"... (2 Replies)
Discussion started by: larry
2 Replies
Login or Register to Ask a Question