Sort by alpha then by number


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sort by alpha then by number
# 1  
Old 09-09-2013
Sort by alpha then by number

I have a file like the following:

Code:
/vol/release
/vol/listing
/vol/trees7
/vol/toperforce
/vol/trees10
/vol/trees2
/vol/wtrain

I have tried the following:

Code:
cat file | sort -t/ -dfk3.1 -t/ -k3.6n

That did not work. What I want to do is have the file sorted so that the first character is used in the sort and then after the list is assembled alphabetically, the 6th character of the third column is used in a sort. So the file should look like this:

Code:
/vol/listing
/vol/release
/vol/toperforce
/vol/trees2
/vol/trees7
/vol/trees10
/vol/wtrain

What keeps happening is I can get the column sorted alphabetically or numberically by the 6th digit of the third column but not by both. Is this even possible? I'd like it to arrange everything alphabetically and then put the trees so that trees2, trees7 and trees10 are in numerical order. I've also tried to use cut to chop off the "vol" part and just use one column but this did not work either. Any suggestions?
# 2  
Old 09-09-2013
Try:
Code:
sort -t/ -k3.1,3.5 -k3.6,3n file

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 09-09-2013
Thanks, this works great!

Thanks this works great! I can't believe how much this command can do. I'll have to study all the options further.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print column number while ignoring alpha characters

I have the following script that will print column 4 ("25") when column 1 contains "123". However, I need to ignore the alpha characters that are contained in the input file. If I were to ignore the characters my output would be column 3. What is the best way to print my column of interest... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

2. Shell Programming and Scripting

Sort from highest to lowest number

Hi Guys, I am looking for a way to sort the output below from the "Inuse" count from Highest to Lowest. Is it possible? Thanks in advance. user1 0.12 0.06 0 0.12 User Inuse Pin Pgsp Virtual Unit:... (4 Replies)
Discussion started by: jaapar
4 Replies

3. Shell Programming and Scripting

Sort Decimal number in UNIX

Hello Everyone, In one of my script, I would like to sort the decimal numbers. For e.g. If I have numbers like 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.10 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 I would like to sort them 1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.2 7.3 7.4... (3 Replies)
Discussion started by: sachinrastogi
3 Replies

4. Shell Programming and Scripting

Help with sort word followed by exponential number and numeric number at the same time

Input file: ID_34 2E-69 2324 ID_1 0E0 3254 ID_1 0E0 5434 ID_5 0E0 436 ID_1 1E-14 2524 ID_1 5E-52 46437 ID_3 65E-20 45467 ID_1 0E0 6578 ... Desired output file: ID_1 0E0 6578 ID_1 0E0 5434 ID_1 0E0 3254 ID_1 5E-52 46437 ID_1 1E-14 2524 ID_3 65E-20 45467 (5 Replies)
Discussion started by: cpp_beginner
5 Replies

5. Shell Programming and Scripting

How to sort the files according to the number?

Hi Everyone, I have a question: I have a lot of file named like or10000.dat, or9100.dat, or100.dat, or3100.dat... I want to deal with these files according to the number in the name. So I want to deal with or100.dat first and then or3100.dat and so on. I used : for i in `ls or*.dat |... (11 Replies)
Discussion started by: wxuyec
11 Replies

6. Shell Programming and Scripting

How can I sort by n number is like words?

I want to sort a file with a list of words, in order of most occuring words to least occurring words as well as alphabetically. ex: file1: cat 3 cat 7 cat 1 dog 3 dog 5 dog 9 dog 1 ape 4 ape 2 I want the outcome to be: file1.sorted: dog 1 (12 Replies)
Discussion started by: castrojc
12 Replies

7. Linux

How to sort the number of occurrences

file:///C:/Users/TSHEPI%7E1.LEB/AppData/Local/Temp/moz-screenshot.pngATM@ubuntu:~$ cat numbers2 | sort -n | uniq -c 1 7 1 11 2 10 3 the 1st numbers are the counts from the command "uniq -c", which represent the number of occurrences of each in the file. The "sort -n"... (4 Replies)
Discussion started by: lebogot
4 Replies

8. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

9. UNIX for Dummies Questions & Answers

Why doesn't sort -k $number work ??

I know this seems like a stupid question. I am trying to sort an address book. Some peole have first, middle and last names, some only have first and last names. Eg: Bob Hope John Bon Jovi etc .. I want to sort this by last name. I was thinking of using something like sort -k $variable... (5 Replies)
Discussion started by: kevin80
5 Replies
Login or Register to Ask a Question