LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2020, 11:08 PM   #1
spellinator
Member
 
Registered: Oct 2007
Location: Dallas, TX
Distribution: CentOS, Ubuntu
Posts: 31

Rep: Reputation: Disabled
Sorting with Multiple Keys


I've tried Googling.
I've tried searching this forum.
I've done trial and error.
Still can't get it right.

Here's the command I'm using and the results I'm getting. First sort by game name works. Second sort by high score does not.

The secondary sort is not sorting the numbers in reverse numeric order. What am I missing here?

File attached if you want to play along. Spaces in original file are tabs.

[root@zeta ~]# sort -k 2 -k 3,3rn test.txt
Johnny Frogger 123100
Olivia Frogger 133500
Liz Frogger 75700
Danny Galaxian 151300
Corey Galaxian 52310
Sam Galaxian 750
Trump MsPacman 10
Courtney MsPacman 17532
Max Pacman 243200
Rachel Pacman 5700
Attached Files
File Type: txt test.txt (201 Bytes, 4 views)
 
Old 07-27-2020, 11:15 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Try -k 2,2 instead of -k 2.

-k 2 assumes that the key starts at field 2 and ends at the end of the line. After that, any further -k options become no-ops, if I understand the man page right.
 
Old 07-27-2020, 11:24 PM   #3
spellinator
Member
 
Registered: Oct 2007
Location: Dallas, TX
Distribution: CentOS, Ubuntu
Posts: 31

Original Poster
Rep: Reputation: Disabled
Thanks.
Looks like that worked.

I thought I had tried that, but I guess I hadn't.

Thanks again!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
create multiple jira issues for multiple jira keys using ansible hruday Linux - Newbie 1 11-26-2018 12:20 PM
Rapid Listing, alphabetically sorting, dir/files sorting in C ? Xeratul Programming 18 11-24-2014 10:13 AM
Bash script for sorting and renaming multiple mp3 files by id3 tags simonloach Linux - General 8 02-16-2013 09:07 AM
bash scripting: sorting and using using multiple files in a script daberkow Linux - Newbie 8 05-28-2009 09:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration