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

  • Home
  • SEARCH
  • 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 8666097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:38:43+00:00 2026-06-12T17:38:43+00:00

I am trying to sort a large (10mb) file on the first 2 columns.

  • 0

I am trying to sort a large (10mb) file on the first 2 columns. The file is delimited by ASCII 241 (±). The problem is that after sorting the first 2 data fields correctly, unix keeps sorting on the rest of the line, regardless of the inclusion of the -s option.

Command : sort -k1bn -k2n -s -t$'\xF1' -o sorted_file file_to_sort

Sample data: (fairly sorted, so I can highlight the issue)

   6033718±2±    0±20817742
   6033718±3±20817742      
   6033718±3±20862761      
   6033718±3±SRDV408BC     
   6033718±3±KFT474        
   6033718±3±941764        
   6033718±4±20817742      
   6033718±4±20862761      
   6033718±4±SRDV408BC     
   6033718±4±KFT474        
   6033718±4±941764        
   6033718±5±21501-0-06   ±D13 * TIMING
   6033718±5±17003-0-01   ±VEHICLE OPER
   6033718±6±21501-0-06   ±10  ±0±     
   6033718±6±17003-0-01   ±10  ±0±     
   6033718±9±I± === Applicable Coverage
   6033718±9±I±Volvo D11/13/16 / TIMING
   6033718±9±E±check for oil leak, insp

After running the command, I get:

   6033718±2±    0±20817742            
   6033718±3±20817742                  
   6033718±3±20862761                  
   6033718±3±941764                    
   6033718±3±KFT474                    
   6033718±3±SRDV408BC                 
   6033718±4±20817742                  
   6033718±4±20862761                  
   6033718±4±941764                    
   6033718±4±KFT474                    
   6033718±4±SRDV408BC                 
   6033718±5±17003-0-01   ±VEHICLE OPER
   6033718±5±21501-0-06   ±D13 * TIMING
   6033718±6±17003-0-01   ±10  ±0±     
   6033718±6±21501-0-06   ±10  ±0±     
   6033718±9±E±check for oil leak, insp
   6033718±9±I± === Applicable Coverage
   6033718±9±I±Volvo D11/13/16 / TIMING

As you can see, looking at the ‘3’, ‘4’ & ‘9’ records, they data following the second field has been sorted, even though the manual for sort states that the -s option will prevent sorting of the rest of the line after the keys have been exhausted.

Where am I going wrong here?

BTW, it seems to work fine on a smaller file.

  • 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-12T17:38:44+00:00Added an answer on June 12, 2026 at 5:38 pm

    The sorting keys are specified as -k <start>[,<end>]. If <end> is not specified, the key used is from <start> to the end of the line, which is somewhat unintuitive. You probably want something more like this:

    sort -k1,1bn -k2,2n -s -t$'\xF1' -o sorted_file file_to_sort
    

    Note these keys specify single fields, rather than the default of “all fields starting at … until the end of the line”.

    • 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 bunch of data such that that the size of
I am trying to sort large inputs in the fastest way in ascending order.
I'm trying to sort a view model binding on multiple properties. The problem is
I'm trying to sort an array that would look something like this: (please ignore
I have two large vectors, I am trying to do some sort of element
I am trying to debug a large and complex webapp that makes heavy use
When I am trying to sort a file and save the sorted output in
I am trying to have some sort of Data Object (I'm thinking a dictionary)
I'm working with a large set of legacy data (converted from a flat-file db),
I am trying to call a C function that is defined in another file.

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.