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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:52:26+00:00 2026-05-22T16:52:26+00:00

I have this file: 100: pattern1 ++++++++++++++++++++ 1:pattern2 9:pattern2 +++++++++++++++++++ 79: pattern1 61: pattern1

  • 0

I have this file:

100: pattern1
++++++++++++++++++++
1:pattern2
9:pattern2
+++++++++++++++++++
79: pattern1
61: pattern1
+++++++++++++++++++

and I want to sort it like this:

++++++++++++++++++++
1:pattern2
9:pattern2
+++++++++++++++++++
61:pattern1
79:pattern1
100:pattern1
+++++++++++++++++++

Is it possible using Linux sort command only ?

If I had :

4:pat1 
3:pat2
2:pat2
1:pat1

O/p should be:

1:pat1
++++++++++++ 
2:pat2
3:pat2
++++++++++++
4:pat1

So, want to sort on first group, but “group” on the pattern of second group.
Please note, the thing after : is a regex pattern not a literal.

  • 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-22T16:52:27+00:00Added an answer on May 22, 2026 at 4:52 pm

    I don’t believe sort alone can do what you need.

    Create a new shell script and put this in its contents (ie mysort.sh):

    #!/bin/sh
    IFS=$'\n' # This makes the for loop below split on newline instead of whitespace.
    delim=+++++++++++++++++++
    for l in `grep -v ^+| sort -g`      # Ignore all + lines and sort by number
    do
        current=`echo $l | sed s/^[0-9]*://g` # Get what comes after the number
        if [ ! -z "$prev" ] && [ "$prev" != "$current" ] # If it has changed...
        then                                  #  then output a ++++ delimiter line.
            echo $delim
        fi
        prev=$current
        echo $l                               # Output this line.
    done
    

    To use it, pipe in the contents of your file like so:

    cat input | sh mysort.sh
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file looks like this : 100 50 20 90 4.07498
I have this file file.txt which I want to split into many smaller ones.
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
This sounds like a issue a beginner like me would only have...this is my
Lets say i have something like this: This is file tree.py: class leaf(): def
I'm familiar with the split command in linux. If I have a file that's
I have a file csv file in this format, I would like to generate
I have a property file( actually 100 or more). This is actually placed in
I have a text file and the last 2 lines look like this... Uptime:
I have a file in hdfs with 100 columns, which i want to proces

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.