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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:24:57+00:00 2026-06-07T11:24:57+00:00

I need to sort some data with unix sort but I can’t figure exactly

  • 0

I need to sort some data with unix sort but I can’t figure exactly the right syntax, the data looks like

3.9.1 Step 10:
3.9.1 Step 20:
3.8.10 Step 20:
3.10.2 Step 10:
3.8.4 Step 90:
3.8.4 Step 100:
3.8.4 Step 10:

I want to sort it using first the major number, then the step number, e.g. the data sorted above would look like.

3.8.4 Step 10:
3.8.4 Step 90:
3.8.4 Step 100:
3.8.10 Step 20:
3.9.1 Step 10:
3.9.1 Step 20:
3.10.2 Step 10:

I have found the way to sort by first number on this site:

sort -t. -k 1,1n -k 2,2n -k 3,3n

but I am struggling to now sort by the 3rd column Step number without disturbing the first 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-06-07T11:24:59+00:00Added an answer on June 7, 2026 at 11:24 am

    There’s a fascinating article on re-engineering the Unix sort (‘Theory and Practice in the Construction of a Working Sort Routine’, J P Linderman, AT&T Bell Labs Tech Journal, Oct 1984) which is not, unfortunately, available on the internet, AFAICT (I looked a year or so ago and did not find it; I looked again just now, and can find references to it, but not the article itself). Amongst other things, the article demonstrated that for Unix sort, the comparison time far outweighs the cost of moving data (not very surprising when you consider that the comparison has to compare fields determined per row, but moving ‘data’ is simply a question of switching pointers around). One upshot of that was that they recommend doing what danfuzz suggests; mapping keys to make comparisons easy. They showed that even a simple scripted solution could save time compared with making sort work really hard.

    So, you could think in terms of using a character that’s unlikely to appear in the data file naturally (such as Control-A) as the key field separator.

    sed 's/^\([^.]*\)[.]\([^.]*\)[.]\([^ ]*\) Step \([0-9]*\):.*/\1^A\2^A\3^A\4^A&/' file |
    sort -t'^A' -k1,1n -k2,2n -k3,3n -k4,4n |
    sed 's/^.*^A//'
    

    The first command is the hard one. It identifies the 4 numeric fields, and outputs them separated by the chosen character (written ^A above, typed as Control-A), and then outputs a copy of the original line. The sort then works on the first four fields numerically, and the final sed commands strips off the front of each line up to and including the last Control-A, giving you the original line back again.

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

Sidebar

Related Questions

I need to sort some data that is not coming from a database, but
I have some sort of recursive function, but I need to parse a string,
I've written the following IComparer but I need some help. I'm trying to sort
I am new with Linq and I would like to sort some data that
I'm working on a project for school and need to sort some data. I've
I have some data that looks a bit like this: require(zoo) X <- rbind(c(date='20111001',
I get some data from a WebService, which looks like this Building Address ->
I have a table with some data that looks like: id | type |
hello guys i need to sort some elements of integer in an integer array
Lets say I want to sort some items and need to sort them by

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.