Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:40:15+00:00 2026-05-15T14:40:15+00:00

I would like to sort a file on more fields. A sample tab separated

  • 0

I would like to sort a file on more fields.
A sample tab separated file is:

a   1   1.0
b   2   0.1
c   3   0.3
a   4   0.001
c   5   0.5
a   6   0.01
b   7   0.01
a   8   0.35
b   9   2.3
c   10  0.1
c   11  1.0
b   12  3.1
a   13  2.1

And i would like to have it sorted alphabetically by field 1 (with -d), and when field1 is the same, sort by field 3 (with the -g option).

A didn’t succeed in doing this. My attemps were (with a real TAB character instead of <TAB>):

cat tst | sort -t"<TAB>" -k1 -k3n
cat tst | sort -t"<TAB>" -k1d -k3n
cat tst | sort -t"<TAB>" -k3n -k1d

None of these are working. I’m not sure if sort is even able to do this. I’ll write a script for workaround, so I’m just curious whether there is a solution using only sort.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:40:16+00:00Added an answer on May 15, 2026 at 2:40 pm

    The manual shows some examples.

    In accordance with zseder’s comment, this works:

    sort -t"<TAB>" -k1,1d -k3,3g
    

    Tab should theoretically work also like this sort -t"\t".

    If none of the above work to delimit by tab, this is an ugly workaround:

    TAB=`echo -e "\t"`
    sort -t"$TAB"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that I would like to sort using a date field
I have an array which i would like to sort it based on values
I have an array which i would like to sort it based on values
I have a very large multidimensional array and I would like to sort it
I have an array of appointment objects, and I would like to sort by
I have an input file with two columns of integer values. I would like
I have this bash script which pases a text file and I would like
I would like to sort this array but this code works if I do
I would like to sort the data of a core data NSSet (I know
I would like to sort the characters in a string. E.g. echo cba |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.