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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:02:26+00:00 2026-05-28T08:02:26+00:00

I have a 4-column CSV file. I want to sort the lines, such that,

  • 0

I have a 4-column CSV file. I want to sort the lines, such that, the lines containing any number somewhere within the third column are pushed to the end of the document, lines without numbers in the third column are put to the beginning. How can I sort the file in this way?

Update:

To clarify, I need to move lines which contain any number (i.e. a match for [0-9]) somewhere within the letters of the third column (the third column of the line might contain other symbols). Spaces are not important. E.g.

dog, eats chicken, has 4 legs, does not like cats
cat, eats mice, has a tail, does not like water
mouse, eats bugs, has 4 legs, does not like cats
elephant, eats peanuts, has a trunk, does not like mice

Would be sorted to:

cat, eats mice, has a tail, does not like water
elephant, eats peanuts, has a trunk, does not like mice
dog, eats chicken, has 4 legs, does not like cats
mouse, eats bugs, has 4 legs, does not like cats
  • 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-28T08:02:27+00:00Added an answer on May 28, 2026 at 8:02 am

    This might work for you:

    sed 'h;s/,/\n/2;s/.*\n/0/;s/,.*//;s/[^0-9]//g;G;s/\n/\t/' file | 
    sort -k1,1n -k2 | 
    cut -f2
    

    Explanation:

    • Generate a numeric key using numbers from the 3rd column (if none set the key to 0)
    • Sort by the above key and then by the original file
    • Remove the numeric key
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file that has column values enclosed within double quotes. I
I have a CSV file that has only 1 column, but has close to
I have a simple report that I want to export to a CSV file.
I have csv file with 14 columns and I want to sort it in
I have a csv file with 7 fields of data. I want to sort
I have a CSV file. The first row will always contain column headers. Depending
I have a CSV data file with rows that may have lots of columns
I have a csv that looks like this: blah,blah, blah, blah ect, ect,column 3
I have a csv file like 120 column by 4500 row. I read the
I have this .csv file: ID,GRADES,GPA,Teacher,State 3,C,2,Teacher3,MA 1,A,4,Teacher1,California And what I want to do

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.