Sponsored Content
Top Forums Shell Programming and Scripting Sorting times and in different ranks Post 302961462 by Don Cragun on Sunday 29th of November 2015 09:40:22 PM
Old 11-29-2015
Sort terminates numeric fields with characters that are not part of a decimal number with an optional fractional part. And, since a colon is not a valid character in a decimal number, you are just sorting on the hours as your primary key and the entire line as an alphanumeric string as your secondary key. The following seems to do what you want:
Code:
LC_NUMERIC="C" sort -t':' -k1.4,1n -k2,2n -k3,3n filename

yielding the output:
Code:
# key: sex, time, athlete, athlete's nationality, date, city, country
M, 1:12:34.6, Fast Guy, GER, 2014-06-16, Konstanz, Germany
M, 2:3:38, Patrick Makau Musyoki, KEN, 2011-09-11, Berlin, Germany
M, 2:3:58.2, Haile Gebrselassie, ETH, 2008-09-28, Berlin, Germany
M, 2:4:15, Geoffrey Mutai, KEN, 2012-09-09, Berlin, Germany
M, 2:4:26, Haile Gebrselassie, ETH, 2007-09-30, Berlin, Germany
M, 2:4:26.3, Duncan Kibet, KEN, 2009-04-05, Rotterdam, Netherlands
M, 2:4:48, Patrick Makau Musyoki, KEN, 2010-04-11, Rotterdam, Netherlands
M, 2:4:55, Paul Tergat, KEN, 2003-09-28, Berlin, Germany
M, 2:5:37.8, Khalid Khannouchi, USA, 2002-04-14, London, UK
M, 2:5:42, Khalid Khannouchi, MAR, 1999-10-24, Chicago, USA
M, 2:5:56, Haile Gebrselassie, ETH, 2006-09-24, Berlin, Germany
M, 2:6:5, Ronaldo da Costa, BRA, 1998-09-20, Berlin, Germany
M, 2:6:16, Evans Rutto, KEN, 2004-10-10, Chicago, USA
M, 2:6:19.5, Haile Gebrselassie, ETH, 2005-10-16, Amsterdam, Netherlands
M, 2:6:36, António Pinto, POR, 2000-04-16, London, UK
M, 2:6:50, Belayneh Dinsamo, ETH, 1988-04-17, Rotterdam, Netherlands
M, 2:6:50, Josephat Kiprono, KEN, 2001-04-22, Rotterdam, Netherlands
M, 2:7:2, Sammy Lelei, KEN, 1995-09-24, Berlin, Germany
M, 2:7:10, Khalid Khannouchi, MAR, 1997-10-19, Chicago, USA
M, 2:7:12, Carlos Lopes, POR, 1985-04-20, Rotterdam, Netherlands
M, 2:7:15, Cosmas Ndeti, KEN, 1994-04-18, Boston, USA
M, 2:7:51, Robert de Castella, AUS, 1986-04-21, Boston, USA
M, 2:8:1, Juma Ikangaa, TAN, 1989-11-05, New York, USA
M, 2:8:5, Steve Jones, WAL, 1984-10-21, Chicago, USA
M, 2:8:7, David Tsebe, RSA, 1992-09-27, Berlin, Germany
M, 2:8:16, Steve Moneghetti, AUS, 1990-09-30, Berlin, Germany
M, 2:8:18, Robert de Castella, AUS, 1981-12-06, Fukuoka, Japan
M, 2:8:18, Takeyuki Nakayama, JPN, 1987-12-06, Fukuoka, Japan
M, 2:8:25, Martín Fiz, ESP, 1996-03-24, Kyong_Ju, South Korea
M, 2:8:37, Robert de Castella, AUS, 1983-04-09, Rotterdam, Netherlands
M, 2:8:51, Dionicio Ceron, MEX, 1993-12-05, Fukuoka, Japan
M, 2:8:52, Alberto Salazar, USA, 1982-04-19, Boston, USA
M, 2:8:53, Koichi Morishita, JPN, 1991-02-03, Beppu, Japan
M, 2:9:1, Gerard Nijboer, NED, 1980-04-26, Amsterdam, Netherlands
M, 2:9:5.6, Shigeru So, JPN, 1978-02-05, Beppu, Japan
M, 2:9:12, Ian Thompson, ENG, 1974-01-31, Christchurch, New Zealand
M, 2:9:28, Bill Rodgers, USA, 1979-04-16, Boston, USA
M, 2:9:28.8, Ron Hill, ENG, 1970-07-23, Edinburgh, Scotland
M, 2:9:36.4, Derek Clayton, AUS, 1967-12-03, Fukuoka, Japan
M, 2:9:55, Waldemar Cierpinski, GDR, 1976-07-31, Montreal, Canada
M, 2:9:56, Bill Rodgers, USA, 1975-04-21, Boston, USA
M, 2:10:30, Frank Shorter, USA, 1972-12-03, Fukuoka, Japan
M, 2:10:47.8, Bill Adcocks, ENG, 1968-12-08, Fukuoka, Japan
M, 2:10:55.3, Bill Rodgers, USA, 1977-12-04, Fukuoka, Japan
M, 2:11:7.2, Bill Adcocks, ENG, 1969-04-06, Athens, Greece
M, 2:11:8.8, Derek Clayton, AUS, 1971-09-25, Hobart, Australia
M, 2:11:12.6, John Farrington, AUS, 1973-07-14, Sydney, Australia
M, 2:12:0, Morio Shigematsu, JPN, 1965-06-12, Chiswick, England
M, 2:12:11.2, Abebe Bikila, ETH, 1964-10-21, Tokyo, Japan
M, 2:14:4.8, Michael Ryan, NZL, 1966-11-27, Fukuoka, Japan
M, 2:14:28, Leonard Edelen, USA, 1963-06-15, Chiswick, England
M, 2:15:16.2, Abebe Bikila, ETH, 1960-09-10, Rome, Italy
M, 2:15:17.6, Sergei Popov, URS, 1958-08-24, Stockholm, Sweden
F, 2:15:24.6, Paula Radcliffe, ENG, 2003-04-13, London, UK
M, 2:16:9.6, Yu Mang_Hyang, PRK, 1962-10-24, Pyongyang, North Korea
F, 2:17:17.7, Paula Radcliffe, ENG, 2002-10-13, Chicago, USA
M, 2:17:39.4, Jim Peters, ENG, 1954-06-26, Chiswick, England
F, 2:17:42, Paula Radcliffe, ENG, 2005-04-17, London, UK
M, 2:17:45.2, Sergei Popov, URS, 1959-11-11, Košice, Slovakia
M, 2:18:4.8, Paavo Kotila, FIN, 1956-08-12, Pieksämäki, Finland
F, 2:18:20, Liliya Shobukhova, RUS, 2011-10-09, Chicago, USA
M, 2:18:34.8, Jim Peters, ENG, 1953-10-04, Turku, Finland
F, 2:18:37, Mary Keitany, KEN, 2012-04-22, London, UK
F, 2:18:47, Catherine Ndereba, KEN, 2001-10-07, Chicago, USA
M, 2:18:54, Takayuki Nakao, JPN, 1961-03-21, Nagoya, Japan
F, 2:19:19, Irina Mikitenko, GER, 2008-09-28, Berlin, Germany
F, 2:19:36, Deena Kastor, USA, 2006-04-23, London, UK
F, 2:19:41, Yoko Shibui, JPN, 2004-09-26, Berlin, Germany
M, 2:19:50, Sergei Popov, URS, 1957-09-01, Moscow, Russia
F, 2:20:25, Liliya Shobukhova, RUS, 2010-10-10, Chicago, USA
F, 2:20:38, Zhou Chunxiu, CHN, 2007-04-22, London, UK
M, 2:20:42.2, Jim Peters, ENG, 1952-06-14, Windsor, England
F, 2:20:43, Tegla Loroupe, KEN, 1999-09-26, Berlin, Germany
F, 2:20:47, Tegla Loroupe, KEN, 1998-04-19, Rotterdam, Netherlands
F, 2:21:6, Ingrid Kristiansen, NOR, 1985-04-21, London, UK
M, 2:21:21.6, Veikko Karvonen, FIN, 1955-09-04, Copenhagen, Denmark
F, 2:21:33, Catherine Ndereba, KEN, 2000-10-22, Chicago, USA
F, 2:21:45, Uta Pippig, GER, 1994-04-18, Boston, USA
F, 2:22:7, Tegla Loroupe, KEN, 1997-04-20, Rotterdam, Netherlands
F, 2:22:11, Irina Mikitenko, GER, 2009-04-26, London, UK
F, 2:22:43, Joan Benoit, USA, 1983-04-18, Boston, USA
F, 2:22:48, Ingrid Kristiansen, NOR, 1987-05-10, London, UK
F, 2:23:43, Olga Markova, RUS, 1992-04-20, Boston, USA
F, 2:23:51, Lisa Ondieki, AUS, 1988-01-31, Osaka, Japan
F, 2:24:7, Wang Junxia, CHN, 1993-04-04, Tianjin, PR China
F, 2:24:18, Wanda Panfil, POL, 1991-04-15, Boston, USA
F, 2:24:26, Ingrid Kristiansen, NOR, 1984-05-13, London, UK
F, 2:24:33, Ingrid Kristiansen, NOR, 1989-04-17, Boston, USA
F, 2:24:54, Grete Waitz, NOR, 1987-04-20, London, UK
F, 2:25:11, Uta Pippig, GER, 1995-04-17, Boston, USA
F, 2:25:24, Rosa Mota, POR, 1990-04-16, Boston, USA
F, 2:26:4, Katrin Dörre, GER, 1996-01-28, Osaka, Japan
F, 2:26:12, Joan Benoit, USA, 1982-09-12, Eugene, USA
M, 2:26:14, Sohn Kee_Jung, KOR, 1935-03-21, Tokyo, Japan
F, 2:26:47, Allison Roe, NZL, 1981-04-20, Boston, USA
M, 2:28:7.4, Veikko Karvonen, FIN, 1951-08-03, Tampere, Finland
M, 2:28:32, Sohn Kee_Jung, KOR, 1936-04-18, Tokyo, Japan
M, 2:28:39.4, Salomon Könönen, FIN, 1949-10-02, Turku, Finland
M, 2:29:9.4, Fedosiy Vanin, URS, 1950-07-12, Moscow, Russia
F, 2:30:27, Joyce Smith, ENG, 1980-11-16, Tokyo, Japan
M, 2:30:27.6, Pat Dengis, USA, 1938-05-30, Salisbury, Massachusetts, USA
M, 2:30:38, Manuel Dias, POR, 1937-03-28, Lisbon, Portugal
M, 2:30:57.6, Harry Payne, GBR, 1929-07-05, Stamford Bridge, England
M, 2:30:58, Mikko Hietanen, FIN, 1947-08-23, Loughborough, England
M, 2:31:2, Mikko Hietanen, FIN, 1948-09-07, Stockholm, Sweden
M, 2:31:10, Kozo Kusunoki, JPN, 1933-11-03, Tokyo, Japan
M, 2:31:26, Toyu Ko, KOR, 1939-11-03, Tokyo, Japan
M, 2:31:27, Les Pawson, USA, 1941-05-30, Salisbury, Massachusetts, USA
M, 2:31:31, Tnji Yahagi, JPN, 1932-04-30, Tokyo, Japan
M, 2:31:37, Mikko Hietanen, FIN, 1946-07-11, Imatra, Finland
M, 2:31:38, Zaiten Kimoto, JPN, 1942-11-02, Tokyo, Japan
M, 2:32:56, Tamao Shiaku, JPN, 1934-11-23, Osaka, Japan
M, 2:32:57, Boughera El Ouafi, FRA, 1928-08-05, Amsterdam, Netherlands
M, 2:33:19, Juan Zabala, ARG, 1931-10-28, Košice, SVK
M, 2:33:42, Shoichiro Takenaka, JPN, 1940-11-01, Tokyo, Japan
M, 2:34:25, Iivari Rötkö, FIN, 1926-09-12, Helsinki, Finland
M, 2:35:21.4, Verner Laaksonen, FIN, 1927-09-11, Helsinki, Finland
M, 2:35:59, Sam Ferris, ENG, 1925-05-30, Windsor, England
M, 2:36:10, Shizo Kanaguri, JPN, 1924-04-12, Tokyo, Japan
M, 2:36:33, Fukutaro Shibui, JPN, 1930-05-28, Tokyo, Japan
M, 2:36:37.6, Sven Hakansson, SWE, 1945-10-28, Gothenburg, Sweden
M, 2:38:35.3, Gérard Côté, CAN, 1943-11-07, Yonkers, New York, USA
M, 2:40:47, Aksel Jensen, DEN, 1923-06-16, Windsor, England
M, 2:40:48.6, Charles Robbins, USA, 1944-11-12, Yonkers, New York, USA
M, 2:46:26, Gabriel Ruotsalainen, FIN, 1922-09-10, Helsinki, Finland
M, 2:47:29.8, Florestano Benedetti, ITA, 1921-09-20, Bologna, Italy
M, 3:12:34.6, Slow Guy, GER, 2014-06-16, Constant, Germany

with your sample input.
This User Gave Thanks to Don Cragun For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Boot times

Hey all, What we have at work is a Themis board (VME rack SPARC system). We have to try to have the boot time as fast as can be. What we have already done is make some filesystems read only so if power is lost then the filesystem check will not run. This is only done to the partitions that... (2 Replies)
Discussion started by: woofie
2 Replies

2. AIX

how would you know your server was rebooted 3 times or 5 times

Is there such location or command to know how many times did you reboot your server in that particular day?in AIX. (3 Replies)
Discussion started by: kenshinhimura
3 Replies

3. UNIX for Dummies Questions & Answers

comparing two times

Hi Good Morning all, I have two dates and times in the beloe format. 1. 07/18/2009 03:45:49 2. 07/18/2009 03:46:41 i will grep these values from a file. Now my problem is i need to find out whether the second valus is bigger thatn the 1 value. How to compare the times. Please help me in... (4 Replies)
Discussion started by: intiraju
4 Replies

4. Shell Programming and Scripting

Exit if between 2 times

Hello, I am working in Solaris 10 with a Bash script and trying to figure out how I can tell the script to look at the day of the week and the time and for example if it is Sat between 5:50am and 6:30am then just exit out of the script. Any other day or time keep running. We have a... (3 Replies)
Discussion started by: LRoberts
3 Replies

5. UNIX and Linux Applications

ssh times out

I have fedora 13 installed on my home computer. I am unable to ssh from my office to my home computer. On trying to ssh to my home computer, I get the following response: $ ssh -vvv username@129.X.XXX.XXX OpenSSH_5.3p1, OpenSSL 1.0.0a-fips 1 Jun 2010 debug1: Reading configuration data... (6 Replies)
Discussion started by: arbitguy
6 Replies

6. Shell Programming and Scripting

Listing times from ls

Hello, Im new to shell scripting and i am trying to write a part of my script that will search for all files in any given folder and write down all the names of the files and the atime, change time, and modtime of the files in one file as an output. I know that ls -l, ls -ul and ls -lc will give... (1 Reply)
Discussion started by: jnagda
1 Replies

7. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

8. Red Hat

Response Times

Hello all. Let me qualify my question by saying that I am struggling with how to ask the question I am semi green but have no issue reading up if pointed in the right direction. Please be gentle! A RHEL server 6.2. Hosts a statistical application that has some web apps and batch programming... (0 Replies)
Discussion started by: rsheikh01
0 Replies

9. Linux

Accessing Few DDR Ranks

Hi, Considering a case there are 4 RANKs in a DIMM. Run time, if one of the 4 rank has fault which results into use 3 ranks. Say Rank1 has faults. So Rank0, Rank2 and Rank3 are operational. Is it possible case? If above is true then, who is responsible for address aliasing? Memory Controller... (4 Replies)
Discussion started by: Dhaval Shah
4 Replies
All times are GMT -4. The time now is 05:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy