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 6893779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:42:04+00:00 2026-05-27T06:42:04+00:00

I am trying to sort a table based on the first value from smallest

  • 0

I am trying to sort a table based on the first value from smallest to largest with the gnu-coreutils sort command.

My table looks something like this:

file.txt

100,0.8,0.323, ... some more data
2,0.323,0,323, ...
4, ...
53, ...
.
.
121, ...

I have tried doing the following:

sort -n -k 1 file.txt

but I get things like…

10,0,10,10
100,9,1,10
101,9,2,11
102,9,3,12
103,9,4,13
104,9,5,14
105,9,6,15
106,9,7,16
107,9,8,17
108,9,9,18
21,1,10,11
32,2,10,12
43,3,10,13
54,4,10,14

I want the logical numerical order.

Ted.

  • 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-27T06:42:05+00:00Added an answer on May 27, 2026 at 6:42 am

    The correct invocation of sort might look like

    $ sort -n -t , -k 1,1 file.txt
    

    Explanation:

    • -n sort numerically
    • -t , comma is field separator
    • -k 1,1 sort on the first field
    • file.txt input file

    Invoking the above given program gives

    10,0,10,10
    21,1,10,11
    32,2,10,12
    43,3,10,13
    54,4,10,14
    100,9,1,10
    101,9,2,11
    102,9,3,12
    103,9,4,13
    104,9,5,14
    105,9,6,15
    106,9,7,16
    107,9,8,17
    108,9,9,18

    When sorting by fields it is very handy to use --debug option, just to make sure that sort works as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to sort a user table based on how many comments they have
I am trying to sort a dict based on its key and return an
I'm trying to make sections in a table view based on the alphabet and
I'm trying to write Linq query on this Products table based on FacetTypes that
I'm trying to sort a table with javascript Date objects in one of the
I'm trying to build a user based message system. I'd like messages to show
Im trying to eliminate two tables from my database. The tables are message_sort_options and
I'm trying to render the sortable table that's provided in Google visualization API in
Trying to sort this array of objects according to (1) depth and (2) weight,
I am trying to sort a list using delegates but I am getting a

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.