Sorting a column according to the number of names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting a column according to the number of names
# 1  
Old 05-21-2018
Hammer & Screwdriver Sorting a column according to the number of names

Hey,
So I'm having issues sorting a data set.
The data set contains entries as such;

Code:
# key: sex, time, athlete, athlete's nationality, date, city, country

M, 2:30:57.6, Harry Payne, GBR, 1929-07-05, Stamford Bridge, England
M, 2:5:42, Khalid Khannouchi, MAR, 1999-10-24, Chicago, USA
M, 2:5:37.8, Khalid Khannouchi, USA, 2002-04-14, London, UK
M, 2:4:48, Patrick Makau Musyoki, KEN, 2010-04-11, Rotterdam, Netherlands

I now want to sort this file according to the name of the athlete's, however, I don't want to sort it alphabetically but according to the number of names the athletes have. So for instance, I would like to sort the entire document starting with the entries of all the athletes that have 2-word names, then all the athletes with 3-word names and so on. Is this possible using sort?

I have tried various commands;

Code:
sort -k 4-5|4-6 t22 > t22a

sort -k 4,5 | sort -k 4,6 t22 > t22a

sort -kb 4 t22 > t22a

sort -k 4 -b t22 > t22a

But I haven't managed to sort the data in the way I want it.
Does anyone know what I'm doing wrong?
Thanks in advance for your help.
Smilie
# 2  
Old 05-21-2018
Duplicate thread - continue here.
Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Sorting a column based on another column

hello, I have a file as follows: F0100010 A C F0100040 A G BTA-28763-no-rs 77.2692 F0100020 A G F0100030 A T BTA-29334-no-rs 11.4989 F0100030 A T F0100020 A G BTA-29515-no-rs 127.006 F0100040 A G F0100010 A C BTA-29644-no-rs 7.29827 F0100050 A... (9 Replies)
Discussion started by: Homa
9 Replies

2. Shell Programming and Scripting

sorting file names with hyphen and underscore

Hi, I have two types of file names filename1_12345 or filename1-12345 at the same time I have second type filename2-12345 in a txt file. I am trying to write awk script that will sort these names with below pattern ALL file names like filename1_12345 and filename1-12345 will go to... (1 Reply)
Discussion started by: rider29
1 Replies

3. Shell Programming and Scripting

Sorting file based on names

Hi I have some files in directory and the names of files are like jnhld_15233_2010-11-23 jnhld_15233_2007-10-01 jnhld_15233_2001-05-04 jnhld_15233_2011-11-11 jnhld_15233_2005-06-07 jnhld_15233_2000-04-01 ..etc How can i sort these files based on the date in the file name so that ... (4 Replies)
Discussion started by: morbid_angel
4 Replies

4. Shell Programming and Scripting

sorting on one column

Hello all, Is there a way to sort only one column while keeping everything else intact. Take for example this situation: (all columns are space separated) 11 AA asdf 1 -0.5 xx 11 AA axdf 1 -0.6 xx 11 AA csls 1 -0.7 xx 11 AA hjkj 1 -0.4 xx 11 AA uius 1 -0.8 xx 22 AA asdf 1 -0.4 xx 22 AA... (7 Replies)
Discussion started by: jaysean
7 Replies

5. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

6. Shell Programming and Scripting

rearrange the column names with comma as column delimiter

Hi, I am new to shell scripting, i have requirement can any one help me out in this regrads, in directory i have file like invoice1.txt, invoice2.txt in each file i have fixed number of columns, 62 in number but they are randomly arranged.like for first file invoice1.txt can have columns... (5 Replies)
Discussion started by: madhav62
5 Replies

7. Shell Programming and Scripting

Sorting name##.name by number only

How do I sort the output of ls rfc1.txt rfc2.txt rfc30.txt rfc17.txt rfc10.txt rfc3.txt rfc22.txt rfc44.txt rfc20.txt and put it in order like this….. rfc1.txt rfc2.txt rfc3.txt rfc10.txt rfc17.txt rfc20.txt rfc22.txt (2 Replies)
Discussion started by: fatman278
2 Replies

8. Shell Programming and Scripting

Change names in a column based on the symbols in another column

If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output). Thanx input1 1 a aaaaa + 2 b bbbbb + 3 c ccccc + 4 d ddddd + 5 e eeeee + 6 f xxxxx + 8 h hhhhh +... (8 Replies)
Discussion started by: repinementer
8 Replies

9. Shell Programming and Scripting

sorting names after doing a find

hi all, is there an easy way in ksh to sort the results of a find in say alphabetical order ?? e.g in my script i am doing a find for all servers find . -name "server.xml" and the output is not in any order. thanks in advance. (4 Replies)
Discussion started by: cesarNZ
4 Replies

10. UNIX for Advanced & Expert Users

Sorting in unix using column number

Hi All, Can anyone tell me how to sort data in a file using the “sort” command? Note that the records in the data file are not separated into fields. I know only the column positions of the data on which sorting should be done. For example say I've to sort based on the data present in between... (1 Reply)
Discussion started by: swat
1 Replies
Login or Register to Ask a Question